I want to add table row dynamically. I tried with online solution but no luck My code:
<script type="text/javascript">
var index = 2;
var chr = 68;
function insertRow(){
var table=document.getElementById("myTable");
var row=table.insertRow(table.rows.length);
var cell1=row.insertCell(0);
var t1=document.createElement("input");
t1.setAttribute('name', "sigID"+index);
t1.setAttribute('value', char(chr));
t1.setAttribute('size', 10);
cell1.appendChild(t1);
var cell2=row.insertCell(1);
var t2=document.createElement("input");
t2.setAttribute("type","text");
t2.setAttribute('name',"pattern"+index);
t2.setAttribute('size',10);
t2.setAttribute('colspan',2);
cell2.appendChild(t2);
index++;
chr++;
}
</script>
I have added one default row in HTML and then on clicking add I want to add row as per the need. HTML Page:
<table id="myTable" style="margin-left:201px;">
<tr>
<th>SigID</th>
<th colspan="2">Patterns</th>
</tr>
<tr>
<td>
{!!Form::text('sigID1','A',array('size'=>'5'))!!}
</td>
<td colspan="2">
{!!Form::text('pattern1','',array('size'=>'102'))!!}
<input type="button" class="btn btn-primary btn-md" onclick="insertRow()" value="Add">
</td>
</tr>
</table>
Please let me know what is wrong in this code.