Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining values from a dynamically created table

Status
Not open for further replies.

rsulliva

Programmer
Dec 28, 2001
2
US
I am trying to access the data contained in dynamically created table rows through the query string. Unfortunately, a submit() doesn't seem to be adding the dynamically created rows to the form data. Any ideas why or how to get around this? Also, for clarity's sake i eliminated the actual data from the table cells. On my actual page I have select boxes within the table cells, but those values are appended in the query string fine for the existing(not dynamically created) table cells.

here is a sample of my code:





<html>
<script language=javascript>
var counter=5;
function newOne() {
mynewrow = document.all.myTable.insertRow();
mynewrow.insertCell();
mynewrow.insertCell();
mynewrow.insertCell();
mynewrow.cells(0).innerHTML = &quot;<td>x</td>&quot;;
mynewrow.cells(1).innerHTML = &quot;<td>y</td>&quot;;
mynewrow.cells(2).innerHTML = &quot;<td>z</td>&quot;;
counter++;
}
function delRow(){
document.all.myTable.deleteRow();
counter--;
}
function checker(){
poster.submit();
}
</script>

<body>
<form name=poster id=poster method=get>
<table id=myTable name=myTable border=&quot;1&quot; onload=javascript:setTable()>
<tr><th>Location</th><th>Department</th><th>Direction</th></tr>
<tr>
<td>x</td>
<td>y</td>
<td>z</td>
</tr>
<tr>
<td>x</td>
<td>y</td>
<td>z</td>
</tr>
<tr>
<td>x</td>
<td>y</td>
<td>z</td>
</tr>
<tr>
<td>x</td>
<td>y</td>
<td>z</td>
</tr>
</table>
<input type=button name=Update value=Update onclick=javascript:checker()>
</form>
<a href=&quot;javascript:newOne()&quot;>Add Row</a>
<a href=&quot;javascript:setTable()&quot;>Reset</a>
<a href=&quot;javascript:delRow()()&quot;>Delete Last Row</a>
</body>
</html>
 
I found two ways of doing it. The first:
mynewrow = document.all.myTable.insertRow();
mynewrow.style.background = &quot;#cccccc&quot;;
mynewrow.insertCell();
mynewrow.insertCell();
mynewrow.insertCell();
mynewrow.insertCell();
mynewrow.cells(0).runtimeStyle.textAlign=&quot;center&quot;;
mynewrow.cells(0).innerHTML = &quot;<td align=center><SELECT id=loc> <OPTION >A<OPTION >B</SELECT></td>&quot;;

the second:
mynewrow = document.all.myTable.insertRow();
var oSelect = document.createElement(&quot;SELECT&quot;);
var Option1 = document.createElement(&quot;OPTION&quot;);
var Option2 = document.createElement(&quot;OPTION&quot;);
Option1.value = x;
Option1.innerText = &quot;a&quot;;
oSelect.appendChild(Option1);
Option2.value = y;
Option2.innerText = &quot;b&quot;;
oSelect.appendChild(Option2);
mynewrow.cells(0).appendChild(oSelect);

i am currently using the first way. The only way i have figured out how to get the actual values is to create my own url
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top