Control over Multiple Group Checkbox in a form

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
thamizh
Forum Newbie
Posts: 18
Joined: Wed Apr 14, 2010 7:25 am

Control over Multiple Group Checkbox in a form

Post by thamizh »

<script language="javascript">
function boxchk1(obj,max) {
var box = obj.name.substr(0,obj.name.lastIndexOf('_')+1);
var cnt=0,i=1;
while(obj.form[box+i])
{
cnt += obj.form[box+i].checked;i++;
}
if (cnt > max)
{
obj.checked = false;
alert('Only choose ' + max + ' '+box.substr(0,box.length-1) +' checkboxes.\nTo pick this option unselect one of the others.');
}
}
</script>


am using above script, this script control all the group checkboxes in the form ,but i have 2 to 3 checkbox group each group should have only one checkbox checked how to do this anybody help me pls :(
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Control over Multiple Group Checkbox in a form

Post by omniuni »

Is there a reason you don't want to use radio buttons instead?
thamizh
Forum Newbie
Posts: 18
Joined: Wed Apr 14, 2010 7:25 am

Re: Control over Multiple Group Checkbox in a form

Post by thamizh »

yes changed all the checkboxes to radio buttons
now i got the desired result thanks a lot :)
Post Reply