[RESOLVED] - load the html text controls dynamically question
if i load the html text controls dynamically how can i reference each one?
these will be read from a database and created in a loop and
could contain 10 or more text objects.
eg: in a loop there could be 10 of these:
<input name="productname" readonly type="text" size="10">
how do i reference each one individually with classic asp?
Thanks Rory - works great!!
Re: load the html text controls dynamically question
not sure exactually wat u mean but ere s sum that might help
<%
for c=1 to 10
response.write("<input name='productname' readonly type='text' size='10'>")
next
%>
hope it helps
Re: load the html text controls dynamically question
sorry for being so vague -
i am loading records from a database into an html table with a loop, so there could be 10 or more <input type="text"...> textbox controls within this form.
If I give a name : <input type="text" name="product"> then in the loop
these textboxes will all have the same name of "product".
<table>
<% while not rs.eof %>
<tr>
<td><input type="text" name="product" value="<%=rs("product")">
</tr>
<% wend %>
</table>
in the small example above each of the text objects have the same name so...
Question is how can I identify each one individually with response.forms() ?
As the select - option has a built in array the textbox does not.
Re: load the html text controls dynamically question
either
<table>
<% while not rs.eof %>
<tr>
<td><input type="text" name="<%=rs("product")%>" value="<%=rs("product")%>">
</td></tr>
<% wend %>
</table>
OR
<table>
<% while not rs.eof %>
<tr>
<td><input type="text" name="<%=rs("ID")%>" value="<%=rs("product")%>">
</td></tr>
<% wend %>
</table>
OR
<table>
<% c = 1: while not rs.eof: c = c+1 %>
<tr><td>
<input type="text" name="product<%=c%>" value="<%=rs("product")%>">
</td></tr>
<% wend %>
</table>
AND .. better coding would be this ..
Code:
<%
Dim sTable
Dim rsProduct
Dim iCnt
iCnt = 0
sTable = ""
sTable = sTable & "<table>" & vbCrLf
Do Until rs.eof
iCnt = iCnt+1
rsProduct = rs("product")
sTable = sTable & "<tr><td>" & vbCrLf
sTable = sTable & "<input type=""text"" name=""product" & iCnt & """ value=""" & rsProduct & """>" & vbCrLf
sTable = sTable & "</td></tr>" & vbCrLf
Loop
sTable = sTable & "</table>" & vbCrLf
%>
<%= sTable %>
OR
Code:
<%
Dim sTble, rsProd, c
c = 0: sTble = ""
sTble = sTble & "<table>" & vbCrLf
Do Until rs.eof: c = c+1
rsProd = rs("product")
sTble = sTble & "<tr><td>" & vbCrLf
sTble = sTble & "<input type=""text"" name=""product" & c & """ value=""" & rsProd & """>" & vbCrLf
sTble = sTble & "</td></tr>" & vbCrLf
Loop
sTble = sTble & "</table>" & vbCrLf
%>
<%= sTble %>