Array of checkboxes...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm using ASP to generate an array of checkboxes and was wondering what was
the best way to do it.

I can't use the same name on all the checks, because I only get "on" for the
checked boxes and nothing with the unchecked boxes.

I can't figure out how to specify an array for the input element name.

When I process the results from the form submission, I need to know the
index of the checkbox in my database, so I figured that I could use the
index as part of the input element's name.


Re: Array of checkboxes...

Quoted text here. Click to load it
<% dim fruitarr, fruit
fruitarr = request.form("fruit")

for each fruit in split(fruitarr,", ")
        response.write "<br>choice: " & fruit

'or you can do it this way

for i = 0 to ubound(split(fruitarr,", "))
        response.write "<br>choice" & i & ": " & fruitarr(i)

'now that you have values do whatever you need to do with your database

<form method="post" action="<%=request.servervariables("SCRIPT_NAME")%>">
<input type="checkbox" value="apples" name="fruit">Apples<br>
<input type="checkbox" value="oranges" name="fruit">Oranges<br>
<input type="checkbox" value="bananas" name="fruit">Bananas<br>
<input type="submit" value="Choose">

Adrienne Boswell
Please respond to the group so others can share

Site Timeline