Current location: Hot Scripts Forums » Programming Languages » ASP » FORM VALIDATION - CHECKBOXES: Driving me crazy!!!


FORM VALIDATION - CHECKBOXES: Driving me crazy!!!

Reply
  #1 (permalink)  
Old 09-10-03, 05:38 PM
seala seala is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation FORM VALIDATION - CHECKBOXES: Driving me crazy!!!

I've been working on this for a week and am a web programmer that kind of learning as I go and I think this is simple, but my brain is fried........

How would I:
1) loop thru form to create array for each set of checkboxes with the same name
2) loop thru each array to make sure at least one checkbox has
been selected from each group - if not ... alert "Must
select at leach one checkbox from each Category"

Maybe create a validation function?:
whichCheckBoxArray = the Name of the checkbox to be checked, a string
myMin = 1 (the least you want the user to be able to check, an integer)


for all elements in form of type checkbox, named (var), make sure at
least one checkbox is selected

run function on submit......then proceed to next page if all is well

example sets:
<form action="add_selections.asp" method="post" name="subcategory">
<input type="checkbox" name="cksub4200" value=4201">
<input type="checkbox" name="cksub4200" value=4202">
<input type="checkbox" name="cksub4200" value=4203">
<input type="checkbox" name="cksub4200" value=4204">
<input type="checkbox" name="cksub4200" value=4205">
<input type="checkbox" name="cksub4200" value=4206">
<input type="checkbox" name="cksub4200" value=4207">
<input type="checkbox" name="cksub4200" value=4208">
<input type="checkbox" name="cksub4200" value=4209">

<input type="checkbox" name="cksub4400" value=4401">
<input type="checkbox" name="cksub4400" value=4402">
<input type="checkbox" name="cksub4400" value=4403">
<input type="checkbox" name="cksub4400" value=4404">
<input type="checkbox" name="cksub4400" value=4405">
<input type="checkbox" name="cksub4400" value=4406">

<input type="submit" value="Submit Form"><input type="Reset" value="Reset Form">
</form>

Would really appreciate any help I could get with this.......hair is getting really thin...... Thanks!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-19-03, 11:25 AM
TheLaughingBandit TheLaughingBandit is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
God i love forms.

<SCRIPT LANGUAGE="JavaScript">
function VerifyCheckbox() {
if ((!document.subcategory.cksub4200.a.checked) &&
(!document.subcategory.cksub4200.b.checked) &&
(!document.subcategory.cksub4200.c.checked) &&
(!document.subcategory.cksub4200.d.checked) &&
(!document.subcategory.cksub4200.e.checked) &&
(!document.subcategory.cksub4200.f.checked) &&
(!document.subcategory.cksub4200.g.checked) &&
(!document.subcategory.cksub4200.h.checked) &&
(!document.subcategory.cksub4200.i.checked)) {
alert("You must select from the first group!");
return false;
} else if ((!document.subcategory.cksub4400.j.checked) &&
(!document.subcategory.cksub4400.k.checked) &&
(!document.subcategory.cksub4400.l.checked) &&
(!document.subcategory.cksub4400.m.checked) &&
(!document.subcategory.cksub4400.n.checked) &&
(!document.subcategory.cksub4400.o.checked)) {
alert("You must select from the second group!");
return false;

} else
return true;
}
</script>

<form action="add_selections.asp" method="post" name="subcategory" onSubmit="return VerifyCheckbox()">
<input type="checkbox" id="a" name="cksub4200" value="4201">
<input type="checkbox" id="b" name="cksub4200" value="4202">
<input type="checkbox" id="c" name="cksub4200" value="4203">
<input type="checkbox" id="d" name="cksub4200" value="4204">
<input type="checkbox" id="e" name="cksub4200" value="4205">
<input type="checkbox" id="f" name="cksub4200" value="4206">
<input type="checkbox" id="g" name="cksub4200" value="4207">
<input type="checkbox" id="h" name="cksub4200" value="4208">
<input type="checkbox" id="i" name="cksub4200" value="4209">

<input type="checkbox" id="j" name="cksub4400" value="4401">
<input type="checkbox" id="k" name="cksub4400" value="4402">
<input type="checkbox" id="l" name="cksub4400" value="4403">
<input type="checkbox" id="m" name="cksub4400" value="4404">
<input type="checkbox" id="n" name="cksub4400" value="4405">
<input type="checkbox" id="o" name="cksub4400" value="4406">

<input type="submit" value="Submit Form"><input type="Reset" value="Reset Form">
</form>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-24-03, 05:26 AM
Stealth Stealth is offline
1337 pr0gr4mm3r
 
Join Date: Jun 2003
Location: Glasgow, Scotland
Posts: 188
Thanks: 0
Thanked 0 Times in 0 Posts
you could also try


for each X in request.form("subcategory")
string = string & request.form(X) & "|"
next

subcat_array = Split(string, "|")




tdh i didnt read a lot of ure post so dont blame me if it doesnt help ya
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkboxes on form = mailto recipient. Bojon PHP 4 12-21-04 07:07 PM
asp: URGENT! need to change code to create new form per id seala ASP 2 09-09-03 10:54 PM
asp: validating checkboxes in groups by groupid seala ASP 0 09-08-03 02:36 PM
asp: checkboxes & multi-page form seala ASP 0 09-02-03 02:58 PM
Dynamic form checkboxes (ASP) Claralu ASP 3 08-06-03 04:37 PM


All times are GMT -5. The time now is 09:22 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.