SQL PHP HTML ASP JavaScript articles and free scripts to download

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>
<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.

So now let us split the string to get the array of checked values.

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.
Google+

Tom22-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"
Shashidhara22-02-2013
Thank you.. Useful post..
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer