Click here to Skip to main content
15,392,679 members
Home / Discussions / JavaScript
   

JavaScript

 
Question<SOLVED> Why is my validation script not working? Pin
samflex26-Apr-19 4:20
Membersamflex26-Apr-19 4:20 
AnswerRe: Why is my validation script not working? Pin
Richard Deeming26-Apr-19 4:31
mveRichard Deeming26-Apr-19 4:31 
GeneralRe: Why is my validation script not working? Pin
samflex26-Apr-19 4:45
Membersamflex26-Apr-19 4:45 
GeneralRe: Why is my validation script not working? Pin
Richard Deeming26-Apr-19 4:49
mveRichard Deeming26-Apr-19 4:49 
GeneralRe: Why is my validation script not working? Pin
samflex26-Apr-19 5:04
Membersamflex26-Apr-19 5:04 
Questionjavascript Pin
Member 1418486021-Apr-19 23:48
MemberMember 1418486021-Apr-19 23:48 
AnswerRe: javascript Pin
W Balboos, GHB15-May-19 4:08
mveW Balboos, GHB15-May-19 4:08 
AnswerRe: javascript Pin
Shraddha_Patel5-Nov-19 17:30
MemberShraddha_Patel5-Nov-19 17:30 
You can use this code....
<html>

<head>
    <meta charset="UTF-8">

</head>

<body id="body">

    <div id="wrapper">
        <table align='center' cellspacing=1 cellpadding=1 id="mytable" border=1>
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Type</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody id="tbody">
            </tbody>
        </table>
    </div>
    <button onclick='display()'> Display</button>
    <!--<script src="get-text.js"></script>-->
</body>

</html>


<script>
    var myArray = [{ "name": "aaa", "level": "A" }, { "name": "bbb", "level": "B" }, { "name": "ccc", "level": "C" }];

    function display() {
        var length = myArray.length;
        var htmltext = "";

        for (var i = 0; i < length; i++) {
            console.log(myArray[i]);
            htmltext += "<tr id='table"+i+"'><td>"
            +myArray[i].name+
            "</td><td>"
            +myArray[i].level+
            "</td><td><button onclick='edit("+i+")'>Edit</button><button onclick='remove("+i+")'>Remove</button></td></tr>";
        }
        document.getElementById("tbody").innerHTML = htmltext;
    }

    function edit(indice) {
        var htmltext = "<tr><td><input id='inputname"+indice+"' type='text' value='"
            +myArray[indice].name+
            "'></td><td><input id='inputlevel"+indice+"' type='text' value='"
            +myArray[indice].level+
            "'></td><td><button onclick='save("+indice+")'>Save</button><button onclick='remove("+indice+")'>Remove</button></td></tr>";
        document.getElementById("table"+indice).innerHTML = htmltext; 
    }


    function save(indice) {
        myArray[indice].name = document.getElementById("inputname"+indice).value;
        myArray[indice].level = document.getElementById("inputlevel"+indice).value;
        var htmltext = "<tr id='table"+indice+"'><td>"
            +myArray[indice].name+
            "</td><td>"
            +myArray[indice].level+
            "</td><td><button onclick='edit("
            +indice+")'>Edit</button><button onclick='remove("
            +indice+")'>Remove</button></td></tr>";
        document.getElementById("table"+indice).innerHTML = htmltext;
    }

    function remove(indice) {
        console.log(myArray);
        myArray.splice(indice, 1);
        display();
    }
</script>


modified 6-Nov-19 2:31am.

QuestionAdding Blank pages to PDF when requirements met Pin
Member 142140864-Apr-19 15:03
MemberMember 142140864-Apr-19 15:03 
QuestionRe: Adding Blank pages to PDF when requirements met Pin
Richard MacCutchan4-Apr-19 17:57
mveRichard MacCutchan4-Apr-19 17:57 
AnswerRe: Adding Blank pages to PDF when requirements met Pin
Member 142140864-Apr-19 18:07
MemberMember 142140864-Apr-19 18:07 
GeneralRe: Adding Blank pages to PDF when requirements met Pin
Richard MacCutchan5-Apr-19 5:10
mveRichard MacCutchan5-Apr-19 5:10 
Questionprint array json in dinamic table <html> Pin
serenimus29-Mar-19 11:15
Memberserenimus29-Mar-19 11:15 
AnswerRe: print array json in dinamic table <html> Pin
Richard MacCutchan29-Mar-19 22:29
mveRichard MacCutchan29-Mar-19 22:29 
GeneralRe: print array json in dinamic table <html> Pin
serenimus29-Mar-19 22:50
Memberserenimus29-Mar-19 22:50 
GeneralRe: print array json in dinamic table <html> Pin
Richard MacCutchan29-Mar-19 23:28
mveRichard MacCutchan29-Mar-19 23:28 
GeneralRe: print array json in dinamic table <html> Pin
serenimus30-Mar-19 8:27
Memberserenimus30-Mar-19 8:27 
GeneralRe: print array json in dinamic table <html> Pin
Richard MacCutchan30-Mar-19 21:22
mveRichard MacCutchan30-Mar-19 21:22 
GeneralRe: print array json in dinamic table <html> Pin
serenimus2-Apr-19 8:02
Memberserenimus2-Apr-19 8:02 
GeneralRe: print array json in dinamic table <html> Pin
Richard MacCutchan3-Apr-19 4:47
mveRichard MacCutchan3-Apr-19 4:47 
QuestionChanging a font color Breaks my script??? Pin
Member 1420217628-Mar-19 9:04
MemberMember 1420217628-Mar-19 9:04 
AnswerRe: Changing a font color Breaks my script??? Pin
Richard MacCutchan28-Mar-19 22:42
mveRichard MacCutchan28-Mar-19 22:42 
AnswerRe: Changing a font color Breaks my script??? Pin
Richard MacCutchan29-Mar-19 5:56
mveRichard MacCutchan29-Mar-19 5:56 
QuestionJavascripts documentation engine and API Pin
Yuri_Cherkasov26-Mar-19 2:55
MemberYuri_Cherkasov26-Mar-19 2:55 
QuestionRegular Expression for min of 4 and max 40 characters in TypeScript Pin
simpledeveloper12-Mar-19 7:39
Membersimpledeveloper12-Mar-19 7:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.