PDA

View Full Version : How to handle many items on a form?


gorilla1
03-01-2003, 01:02 AM
I am using asp to layout a series of items and and there are radio buttons next to each item so that viewers can rate them. I am reading the items out of a database. I'm not quite sure how to handle this. Do I make it one form, with one submit, and I index all the names on the form, then search through them all after submit? Or is there is some better way?

G

whammy
03-01-2003, 02:06 AM
It depends on what you're trying to do... can you give us a partial example?

gorilla1
03-01-2003, 02:30 AM
This is the basic idea below.. The ouput would look like
item o 5 o 4 o 3 etc
next item o 5 0 4 03 etc


x=0

do while not eof
read a record
x=x+1
get item from record
Response.Write("<tr><td>item</td>")
Response.Write("<td><input type=""radio"" value=""5"" name=""input(x)"">5</td>")
Response.Write("<td><input type=""radio"" value=""4"" name=""input(x)"">4</td>
etc.")
<input type="hidden" name="litem(x)" value="<% =item(x) %>" >
</tr>")


loop
close file
<input type="submit" value="Submit" >

whammy
03-01-2003, 02:42 AM
OK... in that case it gets a bit more complicated.

If you're using radio buttons or checkboxes, their values won't be sent to the server-side unless they are checked.

Obviously good forms practice comes into play here, but basically with radio buttons you just need to see if a value exists (since they are a single choice from multiple options) by using Request.Form("radiobuttonname").

Where it gets tricky is using checkboxes, since it's multiple choice.

What you need to do in that case is name your checkboxes like this:

MyCheckbox_1
MyCheckbox_2
MyCheckbox_3
MyCheckbox_4

with a value of "X", for instance... so you can check the value of each and figure out what's going on, like

For i = 1 to 4
If Request.Form("MyCheckbox_" & i) = "X" Then
MyCheckboxTotal = MyCheckboxTotal & "X"
Else
MyCheckboxTotal = MyCheckboxTotal & "0"
End If
Next

Then you'd end up with a value like:

X00X

Or whatever, which would tell you what the person checked...

gorilla1
03-01-2003, 06:26 AM
Whammy - Thanks much. Yes, I was able to get the thing to work. It was just hard to visualize it.
G