<form method=post action=form-checkboxck.asp>
<input type=checkbox name=t1 value='cricket'>Cricket
<input type=checkbox name=t1 value='football'>Football
<input type=checkbox name=t1 value='tennis'>Tennis
<input type=checkbox name=t1 value='hockey'>Hockey
<input type=submit value='Submit'>
</form>
Here we have used t1 as common name for all the checkbox with different values so they will be treated as a group of checkbox. Once the form is submitted then the values of the checked checkboxes will be available to the action page and can be collected like this.
Dim mode,mode_a,i
mode=Request("t1")
We have used t1 as the common name so all the values of the checkbox for which the visitor has checked will be available as Request("t1") as comma separated values. So in the above code the variable mode value will be consisting of all checked values separated by comma.
mode_a=split(mode,",")
Now we will loop through the array by using for for loop and UBound function to print out the checked values of the checkboxes.
For i=LBound(mode_a) to UBound(mode_a)
Response.Write mode_a(i) + "<br>"
Next
In PHP similar script to collect checkbox values of a form is available here.
Tom | 22-10-2012 |
Using your "Getting the checked values of checkbox Array of a form in ASP" method, could you tell me how I would also get the unique ID of the checked checkbox in "form-checkboxck.asp" |
Shashidhara | 22-02-2013 |
Thank you.. Useful post.. |