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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submitting value of dynamically created element 1

Status
Not open for further replies.

PoppapumpJ

Programmer
Dec 17, 2001
86
US
I have a table with a hardcoded table and textboxes.

The user can click the "Add Row" button and a new row will be added to the table for them to input text.

Now the question is, why is the data collected in that newly created text box not passed during the submit.

For want it's worth, I am using ASP for ServerSide processing. Form method get is not allowed by comp policy. It has to be submitted via form.

I can access data of text boxes 1-5 because they are Hardcoded in the HTML.

Is there are way to pass the data in the created textboxes

Here is an example of what I am attempting:

[tt]
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>

<script>
function addRow(){
//alert(&quot;got here&quot;)
var numRows = document.all.testTable.rows.length
var newRow = document.all.testTable.insertRow(numRows - 1)
newRow.insertCell(0)
newRow.insertCell(1)
newRow.insertCell(2)

newRow.cells(0).innerHTML = &quot;test&quot;
newRow.cells(1).innerHTML = &quot;<INPUT type='text' name=text'&quot; + (numRows-1) + &quot;'>&quot;
newRow.cells(2).innerHTML = &quot; &quot;
}
</script>

</HEAD>
<BODY>
<%
Response.Write Request.Form(&quot;text6&quot;)


%>


<FORM action=<%=Request.ServerVariables(&quot;URL&quot;)%> method=post>
<TABLE ID=&quot;testTable&quot; border = 1 cellspacing = 0 cellpadding=5>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot; name=text1></TD>
<td> </TD>
</TR>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot; name=text2></TD>
<td> </TD>
</TR>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot; name=text3></TD>
<td> </TD>
</TR>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot;name=text4></TD>
<td> </TD>
</TR>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot; name=text5></TD>
<td> </TD>
</TR>
<TR>
<td colspan=3 align=center><a href=&quot;#&quot; onclick=&quot;javascript: addRow();&quot;>add reject reason</a></TD>
</TR>
</TABLE>


<INPUT type=&quot;submit&quot; value=&quot;Submit&quot; id=submit1 name=submit1>
</form>

</BODY>
</HTML>


[/tt]


Is this even possible
 
instead of using .innerHTML use document.createElement. That way you get a DOM Node object inserted into the tree.

Of course you have to append it to the parent element etc., but anyway i have successfully used it for form submittal.

-pete
 
That's Awesome!!

Thanks


This is an exaple of the code that does what I want

[tt]
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>

<script>
function addRow(){
//alert(&quot;got here&quot;)
var numRows = document.all.testTable.rows.length
var newRow = document.all.testTable.insertRow(numRows - 1)
var newInput = document.createElement(&quot;input&quot;)
document.createElement(&quot;name&quot;)
document.createElement(&quot;value&quot;)
newInput.setAttribute(&quot;name&quot;, &quot;text&quot; + (numRows))
//alert(numRows)

newRow.insertCell(0)
newRow.insertCell(1)
newRow.insertCell(2)

newRow.cells(0).innerHTML = &quot;test&quot;
newRow.cells(1).appendChild(newInput); //.innerHTML = &quot;<INPUT type='text' name=text'&quot; + (numRows-1) + &quot;'>&quot;
newRow.cells(2).innerHTML = &quot;&nbsp&quot;
}
</script>

</HEAD>
<BODY>
<%
Response.Write Request.Form(&quot;text6&quot;)


%>


<FORM action=<%=Request.ServerVariables(&quot;URL&quot;)%> method=post>
<TABLE ID=&quot;testTable&quot; border = 1 cellspacing = 0 cellpadding=5>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot; name=text1></TD>
<td>&nbsp</TD>
</TR>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot; name=text2></TD>
<td>&nbsp</TD>
</TR>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot; name=text3></TD>
<td>&nbsp</TD>
</TR>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot;name=text4></TD>
<td>&nbsp</TD>
</TR>
<TR>
<TD>test</TD>
<TD><INPUT type=&quot;text&quot; name=text5></TD>
<td>&nbsp</TD>
</TR>
<TR>
<td colspan=3 align=center><a href=&quot;#&quot; onclick=&quot;javascript: addRow();&quot;>add Row</a></TD>
</TR>
</TABLE>

<INPUT type=&quot;button&quot; value=&quot;Button&quot; id=button1 name=button1 onclick=&quot;javascript: alert(document.all.text6.name)&quot;>
<INPUT type=&quot;submit&quot; value=&quot;Submit&quot; id=submit1 name=submit1>
</form>

</BODY>
</HTML>



[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top