alvin890101
alvin890101

Reputation: 57

How to add table row with input text inside the table field

How to add a table row with a text input inside the table field?

var table=document.getElementById("myTable");
var rowCount = table.row.length;
var row=table.insertRow(rowCount);
var cell1=row.insertCell(0);
var cell2=row.insertCell(1);

cell1.innerHTML += "<td class='align-center'>1</td>";
cell2.innerHTML += "<input type='text' class='input-long' name='newcategoryname' value='New Category' onfocus='if(this.value == \"New Category\"){ this.value = \"\"; }' onblur='if(this.value==\"\"){this.value=\"New Category\";}'/>";

Upvotes: 0

Views: 1137

Answers (1)

Ramesh Kotha
Ramesh Kotha

Reputation: 8322

You have to create input element by using createElement method, try this

    var cell1 = row.insertCell(1);
    var element1 = document.createElement("input");
    element1.type = "text";
    element1.name = "txtbox[]";
    cell1.appendChild(element1);

Upvotes: 1

Related Questions