hi,
i want to validate checkboxes where each checkbox has a different name
1.atleast one checkbox should be select.
2.not more than 4 checkboxes should be selected.
can any one tell me how to validate this.
queenc
-1
Junior Poster
Recommended Answers
Jump to PostTry following code
<html> <script lang='javascript'> var checkedcount=0; function validate() { if (checkedcount<=0 || checkedcount>4 ) { alert('Select one to four options!'); return false; } } function checkinfo(chkbox) { if(chkbox.checked==true) checkedcount++; else checkedcount--; } </script> <body> <form name=frm action=some.php method=post> <input type=checkbox id=chk[0] name=chk[0] value=0 onclick='javascript:checkinfo(this);' > …
Jump to Posttry it please
<html> <script lang='javascript'> var count=0; function check(mychkbox) { if(mychkbox.checked==true) count++; else count--; if(count<=0) { alert('Must select one options!'); mychkbox.checked=true; return false; } else if(count>3) { alert('You can maximum Select four options!'); mychkbox.checked=false; return false; } } </script> <body> <input type=checkbox name="chkbox1" value="1" onclick="check(this)" checked="checked" …
All 5 Replies
urtrivedi
276
Nearly a Posting Virtuoso
queenc
-1
Junior Poster
BzzBee
5
Posting Whiz
BzzBee
5
Posting Whiz
BzzBee
5
Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.