...

View Full Version : validate checkbox



xiaodao
03-22-2009, 12:14 PM
Hi

Sorry , need a hint on validating checkbox , make sure at least one checkbox is checked.



<form onClick="return formcheck()" name="checkform">
<input type="checkbox" name="haha[]" value="lala">
<input type="checkbox" name="haha[]" value="yoyo">
<input type="submit" name="submit" value="submit">
</form>


so what i should write this formcheck function



function formcheck() {
if (document.checkform.getElements['checkbox'].checked== false){
alert ('You didn\'t choose any of the checkboxes!');
return false;
}else{
return true;
}
}


is this correct?

abduraooft
03-22-2009, 12:44 PM
See http://www.codingforums.com/showpost.php?p=640112&postcount=5

xiaodao
03-22-2009, 02:33 PM
thanks

pietpetoors
03-23-2009, 12:57 PM
All the examples I have found so far shows something where you have more than one checkbox

I need a code where the visitor only have to check one box before he can continue, do you perhaps have an example of that?

abduraooft
03-23-2009, 01:07 PM
All the examples I have found so far shows something where you have more than one checkbox Which means you haven't check the link in my above post.

Philip M
03-23-2009, 02:42 PM
All the examples I have found so far shows something where you have more than one checkbox

I need a code where the visitor only have to check one box before he can continue, do you perhaps have an example of that?

Do you mean check just one checkbox out of several possible options, or do you mean check a particular single checkbox such as "I agree to the terms and conditions"?

And what do you mean by "continue"? Enable further input fields? Move to another page? Submit a form?

Presumably once having checked the box the user may not uncheck it later on? Or if he is able to uncheck it, what happens then?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum