HarpuaFSB
asked on
Looping through form elements, I'm stuck, help!
Hey all,
This is simple enough, I've done it before but the solution is eluding me and it's driving me nuts. Anyway, in ASP VBScript, I'm looping through a recordset and creating checkboxes:
<INPUT TYPE="CHECKBOX" NAME="chk<% = rsSystem("OrderNumber") %>" VALUE="-1">
Now when I post the form, I need to loop through all checkbox items that were created and retrieve the name and value of each item.
I think I have tried every form of "For Each Item in Request.Form..." I could think of and have had zero success getting the info I'm looking for.
Any ideas?
Thanks,
Tom
This is simple enough, I've done it before but the solution is eluding me and it's driving me nuts. Anyway, in ASP VBScript, I'm looping through a recordset and creating checkboxes:
<INPUT TYPE="CHECKBOX" NAME="chk<% = rsSystem("OrderNumber") %>" VALUE="-1">
Now when I post the form, I need to loop through all checkbox items that were created and retrieve the name and value of each item.
I think I have tried every form of "For Each Item in Request.Form..." I could think of and have had zero success getting the info I'm looking for.
Any ideas?
Thanks,
Tom
First of all, check the HTML of your form page. If all the checkboxes have the SAME name, there's only ONE value being passed so there's nothing to cycle through.
If the checkboxes have different names, let us know -- I know I have this on one of my sites, and I can post the code I use.
If the checkboxes have different names, let us know -- I know I have this on one of my sites, and I can post the code I use.
ASKER
matticus,
Looping through the Request.Forms collection.
I just did a workaround using radio buttons instead but am still interested in the solution for this problem...
Webwoman is onto what I was talking about...
all the checkboxes had different names based on the unique ID from the recordset I was looping through (i.e., order # 190, created a checkbox item named "chk190" value="-1")...then when the user submits the form (using the post method) I need to loop through all the chk___ items and, here's the tricky part, checked OR not, retrieve the item's name and value.
so I'd need to retrieve something like this:
chk190 "" (where "" = blank or not checked)
chk191 -1
chk192 -1
chk193 ""
...etc.
make any more sense?
Thanks...
Looping through the Request.Forms collection.
I just did a workaround using radio buttons instead but am still interested in the solution for this problem...
Webwoman is onto what I was talking about...
all the checkboxes had different names based on the unique ID from the recordset I was looping through (i.e., order # 190, created a checkbox item named "chk190" value="-1")...then when the user submits the form (using the post method) I need to loop through all the chk___ items and, here's the tricky part, checked OR not, retrieve the item's name and value.
so I'd need to retrieve something like this:
chk190 "" (where "" = blank or not checked)
chk191 -1
chk192 -1
chk193 ""
...etc.
make any more sense?
Thanks...
ASKER
matticus,
Looping through the Request.Forms collection.
I just did a workaround using radio buttons instead but am still interested in the solution for this problem...
Webwoman is onto what I was talking about...
all the checkboxes had different names based on the unique ID from the recordset I was looping through (i.e., order # 190, created a checkbox item named "chk190" value="-1")...then when the user submits the form (using the post method) I need to loop through all the chk___ items and, here's the tricky part, checked OR not, retrieve the item's name and value.
so I'd need to retrieve something like this:
chk190 "" (where "" = blank or not checked)
chk191 -1
chk192 -1
chk193 ""
...etc.
make any more sense?
Thanks...
Looping through the Request.Forms collection.
I just did a workaround using radio buttons instead but am still interested in the solution for this problem...
Webwoman is onto what I was talking about...
all the checkboxes had different names based on the unique ID from the recordset I was looping through (i.e., order # 190, created a checkbox item named "chk190" value="-1")...then when the user submits the form (using the post method) I need to loop through all the chk___ items and, here's the tricky part, checked OR not, retrieve the item's name and value.
so I'd need to retrieve something like this:
chk190 "" (where "" = blank or not checked)
chk191 -1
chk192 -1
chk193 ""
...etc.
make any more sense?
Thanks...
checkboxes that are *not* checked in the browser, will *not* be part of the form elements posted.
if there is more then one form-element with the same name, you can loop through those with:
For each element in Request.Form("thesamename" )
Response.write element & "<br>"
Next
(in this case the "element" is the value)
Response.write Request.Form("thesamename" ) & "<br>"
will result in a string with all values, seperated with ", " (comma space).
if there is more then one form-element with the same name, you can loop through those with:
For each element in Request.Form("thesamename"
Response.write element & "<br>"
Next
(in this case the "element" is the value)
Response.write Request.Form("thesamename"
will result in a string with all values, seperated with ", " (comma space).
For a better understanding, you should realize that the form-object, is a collection (you can loop through all elements) of sub-objects which are also collections.
The interesting thing is that the default value of those objects is a string.
Try this:
Response.write Typename(Request.Form)
- it says IRequestDictionary (and not String)
Response.write Typename(Request.Form("som e-element" ))
- it says IStringList (and not String)
But for both:
Response.write Vartype(Request.Form)
Response.write Vartype(Request.Form("some -element") )
will return 8, and vartype 8 means String.
The IRequestDictionary is a sort of Dictionary-object, in which each key contains a IStringList.
The IStringList is a sort of array of strings.
The interesting thing is that the default value of those objects is a string.
Try this:
Response.write Typename(Request.Form)
- it says IRequestDictionary (and not String)
Response.write Typename(Request.Form("som
- it says IStringList (and not String)
But for both:
Response.write Vartype(Request.Form)
Response.write Vartype(Request.Form("some
will return 8, and vartype 8 means String.
The IRequestDictionary is a sort of Dictionary-object, in which each key contains a IStringList.
The IStringList is a sort of array of strings.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
matticus,
Looping through the Request.Forms collection.
I just did a workaround using radio buttons instead but am still interested in the solution for this problem...
Webwoman is onto what I was talking about...
all the checkboxes had different names based on the unique ID from the recordset I was looping through (i.e., order # 190, created a checkbox item named "chk190" value="-1")...then when the user submits the form (using the post method) I need to loop through all the chk___ items and, here's the tricky part, checked OR not, retrieve the item's name and value.
so I'd need to retrieve something like this:
chk190 "" (where "" = blank or not checked)
chk191 -1
chk192 -1
chk193 ""
...etc.
make any more sense?
Thanks...
Looping through the Request.Forms collection.
I just did a workaround using radio buttons instead but am still interested in the solution for this problem...
Webwoman is onto what I was talking about...
all the checkboxes had different names based on the unique ID from the recordset I was looping through (i.e., order # 190, created a checkbox item named "chk190" value="-1")...then when the user submits the form (using the post method) I need to loop through all the chk___ items and, here's the tricky part, checked OR not, retrieve the item's name and value.
so I'd need to retrieve something like this:
chk190 "" (where "" = blank or not checked)
chk191 -1
chk192 -1
chk193 ""
...etc.
make any more sense?
Thanks...
ASKER
Never thought of that, using the same name and assigning the value uniquely.
Good call!
Good call!
[rsSystem("OrderNumber")]
then:
[I think I have tried every form of "For Each Item in
Request.Form...]
are you looping through an item in the Request.Forms collection or a recordset? can you post more of your ASP code? pehaps you're not passing/accessing your form data correctly.
hope i can help.
matt