Checkboxes
Hi,
Can anyone tell me if it is possible to limit the number of choices a user can select when using checkboxes? For example, I'd like to have say 6 different choices. The user can select one or two, but no more than two. Is this possible? Thanks.
Bob
Vincent Puglia posted this at 16:32 — 10th August 2000.
They have: 634 posts
Joined: Dec 1999
Hi,
Yes, you can limit the number of checkboxes selected. The easiest method would be to keep a running total and increment it, if the total reaches or exceeds the max, alert the user
Something like this
function chkTicks(fldObj)
{
if (numOfChks == maxNum)
{
fldObj.checked = false;
alert('you can only check' + maxNum + 'checkboxes');
}
else
{
numOfChks++;
fldObj.checked = true;
}
}
Vinny
Where the world once stood
the blades of grass cut me still
Bob posted this at 19:50 — 10th August 2000.
They have: 117 posts
Joined: Feb 2000
Vinny,
Thanks for the help! I had to add some code to allow the user to unselect a choice and make a different choice if he wanted, but I think I got it all working now. Appreciate it!
Bob
Vincent Puglia posted this at 20:16 — 10th August 2000.
They have: 634 posts
Joined: Dec 1999
Hi bob,
figured you would have to after I posted, but I was too tired to think anymore. Glad it worked out, and no problem on my part.
Vinny
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.