Click to See Complete Forum and Search --> : Request Dynamically Named Checkbox Value


jkarp
10-25-2005, 01:32 PM
Working on a page where checkbox's are generated and named dynamically as below:

***statement within loop****

response.write("<input type='checkbox' name=abox"&i&" checked>")

The variable "i" is used the increment the checkboxes with a unique name. This form posts to another where I try and request the value from the checkbox. Normally I would request the value by doing some thing like this:

If Request("abox")= "on" then

However, since I need to have a variable name I am not sure how to request it. I have tried the example below with no luck. Anyone have any insight on how this should be requested?

If Request("abox"&i)= "on" then

jkarp
10-25-2005, 01:35 PM
it works if I code it like:

If Request("abox0")= "on" then

or

If Request("abox1")= "on" then

But I need to be able to loop through it

Bullschmidt
10-25-2005, 06:27 PM
Actually the concept works fine as I just tested with an ASP page called test.asp with just this on it:

<form id="frmMain" name="frmMain" action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="post">
<input type="text" name="InvID1" size="13" maxlength="10" value="<%= InvID1 %>">
<input type="text" name="InvID2" size="13" maxlength="10" value="<%= InvID2 %>">
<input type="submit" name="btnSubmit" value="Submit">
</form>
<%
Response.Write "Posted values are:" & "<br>"
For I = 1 To 2
Response.Write Request.Form("InvID" & I) & "<br>"
Next
%>

---

So perhaps change this:
response.write("<input type='checkbox' name=abox"&i&" checked>")

To be more like this instead:
Response.Write("<input type='checkbox' name='abox" & i & "' checked>")