now iam trying to add rows dynamically into the table when i click "ADD ROW" button. It should also have the option to delete the selected row. So Please help me to find code....
And also please tell me how to add textarea and radiobutton in to the dynamically created rows..
Here is my code;
[HTML]<html>
<head>
<title>Untitl ed Document</title>
<script language="JavaS cript">
function addRow1(id){
var tbody = document.getEle mentById
(id).getElement sByTagName("TBO DY")[0];
var row = document.create Element("TR")
var td1 = document.create Element("TD")
var chkbox = document.create Element('input' );
chkbox.type='Ch eckbox';
td1.align="cent er";
td1.height="39p x";
td1.appendChild ( chkbox);
var td2 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="2" ;
td2.align="cent er";
td2.appendChild (newTextBox)
var td3 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="2" ;
td3.align="cent er";
td3.appendChild (newTextBox)
var td4 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="2" ;
td4.align="cent er";
td4.appendChild (newTextBox)
var td5 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="2";
td5.align="cent er";
td5.appendChild (newTextBox)
var td6 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="7" ;
td6.align="cent er";
td6.appendChild (newTextBox)
var td8 = document.create Element("TD")
var newRadio = document.create Element('<input name="mmmkk" value="Yes" type="radio" id="yes">');
newRadio.type = 'radio';
var btn=document.cr eateElement('in put');
btn.type='submi t';
btn.value='Edit ';
newRadio.value= 'y';
newRadio.name=" YES"
var newRadio1 = document.create Element('<input name="mmmkk" value="No" type="radio" id="yes">');
newRadio1.type = 'radio';
newRadio1.value ='y';
td8.align="cent er";
td8.appendChild (newRadio);
td8.appendChild (newRadio1);
td8.appendChild (btn);
var td7 = document.create Element("TD");
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="4" ;
td7.align="cent er";
td7.appendChild (newTextBox)
var td9 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'textarea';
newTextBox.Text Mode='MultiLine ';
td9.align="cent er";
td9.appendChild (newTextBox)
var td10 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.text mode='MultiLine ';
td10.align="cen ter";
newTextBox.rows ="15";
td10.appendChil d (newTextBox)
row.appendChild (td1);
row.appendChild (td2);
row.appendChild (td3);
row.appendChild (td4);
row.appendChild (td5);
row.appendChild (td6);
row.appendChild (td7);
row.appendChild (td8);
row.appendChild (td9);
row.appendChild (td10);
tbody.appendChi ld(row);
}
</script>
</head>
<body >
<table>
<tr>
<td>
<table id="myTable" border="2px" cellpadding="0p x" cellspacing="0p x"
width="100%">
<tbody>
<tr>
<td align="center" valign="top" width="7%">Sele ct
</td>
<td align="center" valign="top" width="10%">Qua ntity
</td>
<td align="center" valign="top" width="8%">Leng th
</td>
<td align="center" valign="top" width="7%">Widt h
</td>
<td align="center" valign="top" width="8%">Heig ht
</td>
<td align="center" valign="top" width="14%">Tot al <br/>
Measurement
</td>
<td align="center" valign="top" width="10%">Tot al<br/>
Weight
</td>
<td width="8%" > hgjhgj
</td>
<td align="center" valign="top" width="14%">Pac kage and
Description of Cargo
</td>
<td align="center" valign="top" width="14%">Com ments
</td>
</tr>
<tr>
<td align="center" width="7%">
<input name="" type="checkbox" value="" /> </td>
<td align="center" width="10%">
<input name="" type="text" size="2" /> </td>
<td align="center" width="8%">
<input name="" type="text" size="2" /> </td>
<td align="center" width="7%">
<input name="" type="text" size="2" /> </td>
<td align="center" width="8%">
<input name="" type="text" size="2" /> </td>
<td align="center" width="14%">
<input name="" type="text" size="7" /> </td>
<td align="center" width="10%">
<input name="" type="text" size="4" />
<td width="8%" >
<input type="radio" name="rad" value="" id="">Yes
<input type="radio" name="rad" value="" id="">No
<input type="submit" name="Submit" value="Edit">
</td>
<td align="center" width="14%">
<textarea cols="15"></textarea> </td>
<td align="center" width="14%">
<textarea name="" cols="15"></textarea>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td align="right">
<h3><br/>
<input type="button" value="Add Row"
onclick="addRow 1('myTable')" />
<input name="" type="button" value="Delete Selected
Rows" />
<input name="" type="button" value="Submit" />
</h3>
</td>
</tr>
</table>
</body>
</html>
[/HTML]
Thank You,
waiting for your answer..
Bharath Kumar S
And also please tell me how to add textarea and radiobutton in to the dynamically created rows..
Here is my code;
[HTML]<html>
<head>
<title>Untitl ed Document</title>
<script language="JavaS cript">
function addRow1(id){
var tbody = document.getEle mentById
(id).getElement sByTagName("TBO DY")[0];
var row = document.create Element("TR")
var td1 = document.create Element("TD")
var chkbox = document.create Element('input' );
chkbox.type='Ch eckbox';
td1.align="cent er";
td1.height="39p x";
td1.appendChild ( chkbox);
var td2 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="2" ;
td2.align="cent er";
td2.appendChild (newTextBox)
var td3 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="2" ;
td3.align="cent er";
td3.appendChild (newTextBox)
var td4 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="2" ;
td4.align="cent er";
td4.appendChild (newTextBox)
var td5 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="2";
td5.align="cent er";
td5.appendChild (newTextBox)
var td6 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="7" ;
td6.align="cent er";
td6.appendChild (newTextBox)
var td8 = document.create Element("TD")
var newRadio = document.create Element('<input name="mmmkk" value="Yes" type="radio" id="yes">');
newRadio.type = 'radio';
var btn=document.cr eateElement('in put');
btn.type='submi t';
btn.value='Edit ';
newRadio.value= 'y';
newRadio.name=" YES"
var newRadio1 = document.create Element('<input name="mmmkk" value="No" type="radio" id="yes">');
newRadio1.type = 'radio';
newRadio1.value ='y';
td8.align="cent er";
td8.appendChild (newRadio);
td8.appendChild (newRadio1);
td8.appendChild (btn);
var td7 = document.create Element("TD");
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.size ="4" ;
td7.align="cent er";
td7.appendChild (newTextBox)
var td9 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'textarea';
newTextBox.Text Mode='MultiLine ';
td9.align="cent er";
td9.appendChild (newTextBox)
var td10 = document.create Element("TD")
var newTextBox = document.create Element('input' );
newTextBox.type = 'text';
newTextBox.text mode='MultiLine ';
td10.align="cen ter";
newTextBox.rows ="15";
td10.appendChil d (newTextBox)
row.appendChild (td1);
row.appendChild (td2);
row.appendChild (td3);
row.appendChild (td4);
row.appendChild (td5);
row.appendChild (td6);
row.appendChild (td7);
row.appendChild (td8);
row.appendChild (td9);
row.appendChild (td10);
tbody.appendChi ld(row);
}
</script>
</head>
<body >
<table>
<tr>
<td>
<table id="myTable" border="2px" cellpadding="0p x" cellspacing="0p x"
width="100%">
<tbody>
<tr>
<td align="center" valign="top" width="7%">Sele ct
</td>
<td align="center" valign="top" width="10%">Qua ntity
</td>
<td align="center" valign="top" width="8%">Leng th
</td>
<td align="center" valign="top" width="7%">Widt h
</td>
<td align="center" valign="top" width="8%">Heig ht
</td>
<td align="center" valign="top" width="14%">Tot al <br/>
Measurement
</td>
<td align="center" valign="top" width="10%">Tot al<br/>
Weight
</td>
<td width="8%" > hgjhgj
</td>
<td align="center" valign="top" width="14%">Pac kage and
Description of Cargo
</td>
<td align="center" valign="top" width="14%">Com ments
</td>
</tr>
<tr>
<td align="center" width="7%">
<input name="" type="checkbox" value="" /> </td>
<td align="center" width="10%">
<input name="" type="text" size="2" /> </td>
<td align="center" width="8%">
<input name="" type="text" size="2" /> </td>
<td align="center" width="7%">
<input name="" type="text" size="2" /> </td>
<td align="center" width="8%">
<input name="" type="text" size="2" /> </td>
<td align="center" width="14%">
<input name="" type="text" size="7" /> </td>
<td align="center" width="10%">
<input name="" type="text" size="4" />
<td width="8%" >
<input type="radio" name="rad" value="" id="">Yes
<input type="radio" name="rad" value="" id="">No
<input type="submit" name="Submit" value="Edit">
</td>
<td align="center" width="14%">
<textarea cols="15"></textarea> </td>
<td align="center" width="14%">
<textarea name="" cols="15"></textarea>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td align="right">
<h3><br/>
<input type="button" value="Add Row"
onclick="addRow 1('myTable')" />
<input name="" type="button" value="Delete Selected
Rows" />
<input name="" type="button" value="Submit" />
</h3>
</td>
</tr>
</table>
</body>
</html>
[/HTML]
Thank You,
waiting for your answer..
Bharath Kumar S
Comment