PDA

View Full Version : ListBox with CheckBoxes options


raghupathyr
11-28-2002, 07:31 AM
I need to have a List Box with Check Boxes in my web page. Can somebody please tell me how to go about this.

thanks,
Raghu

glenngv
11-28-2002, 08:45 AM
can you explain further?

raghupathyr
11-28-2002, 11:04 AM
I have a list box in my (ASP) webpage.

<select name="MyLstBox" size="10">
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
</select>

Now I want to have a Check-Box for each item in the List Box. I knew that there is a MULTIPLE property for the <Select> tag, but i don't want to use that.

Please help me. I'm struck here.

whammy
11-28-2002, 12:30 PM
One way:

<input type="checkbox" name="C_1" value="X" />Item 1
<input type="checkbox" name="C_2" value="X" />Item 2
<input type="checkbox" name="C_3" value="X" />Item 3

Then you can loop through each C_:


<%
For loopy = 1 to 3
If Request.Form("C_" & loopy) = "X" Then
'do something
Else
'do something else
End If
Next
%>


to see if it's "X" or not... :)

Also, you can name the checkboxes the same name - then the variable passed to the next page will contain a string of the "checked" checkboxes, which will be comma-delimited, i.e.:

<input type="checkbox" name="C" value="1" />Item 1
<input type="checkbox" name="C" value="2" />Item 2
<input type="checkbox" name="C" value="3" />Item 3

Which if all were checked, Request.Form("C") would be:

1, 2, 3

As for what this has to do with a listbox, I have no idea... if this isn't along the lines of what you're talking about, perhaps you can explain it to us in a lot more detail?

:D