Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. javascript

javascript

Scheduled Pinned Locked Moved JavaScript
javascripttutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 14184860
    wrote on last edited by
    #1

    How to create edit button to table that is being created dynamically so as to edit the row of a table.

    W S 2 Replies Last reply
    0
    • M Member 14184860

      How to create edit button to table that is being created dynamically so as to edit the row of a table.

      W Offline
      W Offline
      W Balboos GHB
      wrote on last edited by
      #2

      Create the button as part of the row and have within the buttons attributes appropriate references to it's particular content. This is a very important technique and I suggest strongly you master the concept of creating references to items concurrently with creating the item.

      Ravings en masse^

      "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

      "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

      1 Reply Last reply
      0
      • M Member 14184860

        How to create edit button to table that is being created dynamically so as to edit the row of a table.

        S Offline
        S Offline
        Shraddha_Patel
        wrote on last edited by
        #3

        You can use this code....

        Name

        Type

        Action

         Display
        
        
        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();
        }
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups