Search code examples
javascriptrow

How to add row in table with Javascript , table value checkbox,textbox,radio,select option?


Click the add button, add a new row to the table

enter image description here


Solution

  • You can create a string similar to your HTML code, that represents the row:

    var new_row='<tr>' 
            + '<td><input type="text" id="firstName" name="firstName"></td>'
            + '<td><input type="text" id="lastName" name="lastName"></td>'
            + '<td><input type="radio" id="gender" name="gender"></td>'
            + '</tr>';
    

    I have created only some part of it, you need to add everything your case requires. Then this JS can be used to add the new row to your table:

    document.getElementById('table_id').append(new_row);