Guest mistersing Posted March 27, 2006 Share Posted March 27, 2006 I'm looking to find out if anyone knows how to restrict the number of options a user can choose within a multiple option form field. Let's say you have a form field that has 11 options available to choose, but you want to limit the user choices to 3 of the 11 that are available. Is this possible and, if so, can anyone shed some light as to how it can be done?thank you. Link to comment Share on other sites More sharing options...
Siddhesh Posted March 27, 2006 Share Posted March 27, 2006 I'm looking to find out if anyone knows how to restrict the number of options a user can choose within a multiple option form field. Let's say you have a form field that has 11 options available to choose, but you want to limit the user choices to 3 of the 11 that are available. Is this possible and, if so, can anyone shed some light as to how it can be done?thank you.<{POST_SNAPBACK}> Can you repeat the question in more simple wayWhat type of option you r talking aboutCheckBoxes,Radio buttons,Multiple selection Dropdowns,or List?By the way the check can be done using javascript in your code Link to comment Share on other sites More sharing options...
scott100 Posted March 27, 2006 Share Posted March 27, 2006 I would use checkboxes, call a javascript function onsubmit to check the form when submitted. In the function check how many boxes have been ticked.If there are more than 3 boxes ticked return false, if equal to or less than 3 return true. <html><head><script type="text/javascript">counter=0;val=true;function result(){ for(i=1;i<=5;i++) { on=document.getElementById(i).checked; if (on==true)counter+=1; }if (counter>3)val=falsealert(val);return val;}</script></head><body><form action="http://www.google.com" onsubmit="return result()"><input type="checkbox" id="1" /><input type="checkbox" id="2" /><input type="checkbox" id="3" /><input type="checkbox" id="4" /><input type="checkbox" id="5" /><input type="submit" value="submit" /></form></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now