By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,932 Members | 1,291 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,932 IT Pros & Developers. It's quick & easy.

Simple check box solution?

P: 36
HI Guys

I have a simple check box form (using GET as the method) with a list of 10 different UK counties. I have validated the form so that users have to select no more and no less than 5 UK counties.

The validation works fine. However, when the form is posted to my next page (myresults.asp), I need the values of the options to output the following in my url, no matter what UK counties they choose or what order they select them in:


" 3=Leeds&county4=Manchester&county5=Liverpool"


" kbox=Leeds&checkbox=Manchester&checkbox=Liverpool"

You can view my full script below. If you have any ideas then that would be great.

I look forward to hearing from you

Rod from the UK

<script Language="JavaScript">
function checkbox_checker()

var checkbox_choices = 0;

for (counter = 0; counter < checkbox_form.checkbox.length; counter++)

if (checkbox_form.checkbox[counter].checked)
{ checkbox_choices = checkbox_choices + 1; }


if (checkbox_choices > 5 )

msg="You're limited to only three selections.\n"
msg=msg + "You have made " + checkbox_choices + " selections.\n"
msg=msg + "Please remove " + (checkbox_choices-5) + " selection(s)."
return (false);

if (checkbox_choices < 5 )

alert("Please select 5 counties. \n" + checkbox_choices + " entered so far.")
return (false);

alert(" *** Thank you for your selection. ***");
return (true);

<form method="get" action="" onsubmit="return checkbox_checker()" name="checkbox_form">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<td width="20%" valign="top">
<input type="checkbox" value="Oxford" name="checkbox">Anglesey<br>
<input type="checkbox" value="Liverpool" name="checkbox">Avon<br>
<input type="checkbox" value="Bedfordshire" name="checkbox">Bedfordshire<br>
<input type="checkbox" value="Berkshire" name="checkbox">Berkshire<br>
<input type="checkbox" value="London" name="checkbox">Borders<br>
<input type="checkbox" value="Buckinghamshire" name="checkbox">Buckinghamshire<br>
<input type="checkbox" value="Cambridgeshire" name="checkbox">Cambridgeshire<br>
<input type="checkbox" value="Manchester" name="checkbox">Central<br>
<input type="checkbox" value="Cheshire" name="checkbox">Cheshire<br>
<input type="checkbox" value="Cleveland" name="checkbox">Cleveland<br>
<input type="checkbox" value="Leeds" name="checkbox">Clwyd<br>

<p align="center">

<input type="submit" value="Compare Counties">

----------SCRIPT END-----------
Nov 7 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,208
you can use


then run through all of them and check for

then change the name of each checkbox to the corresponding name for the form.
Nov 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.