Getting the checked values of checkbox Array of a form in ASP
Checkbox are shown to visitors to get the opinion on a fixed value. Sometime the visitors may have to submit more than one choice out of a group of options so here checkbox can be shown to the visitors. For example we can ask the visitor to submit what are the games they play and we can show a list of games. Visitor may select one or more ( or may select all ) games by clicking the checkboxes. Here choice can be more than one ( In case any one to be selected out of the list then radio button is to be used ) so checkbox is the best option. We will learn how to collect the checked values of the form checkbox inside ASP for further processing. Here is the html form with checkboxes.
<form method=post action=form-checkboxck.asp>
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.
<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'>
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.
So now let us split the string to get the array of checked values.
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)
In PHP similar script to collect checkbox values of a form is available here.
Response.Write mode_a(i) + "<br>"
Number of User Comments : 2
|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" |
|Thank you.. Useful post..|