I'm using a select tag in a form I'm making that allows multiple selections, but I want to make the maximum amount of selections upto 10. Is this possible using javascript or jquery?
Thanks in advance!
I'm using a select tag in a form I'm making that allows multiple selections, but I want to make the maximum amount of selections upto 10. Is this possible using javascript or jquery?
Thanks in advance!
figured it out! here's the resulting code:
Thanks for all your help guys!
This answer works in those cases:
Code:
Demo
Or, for old browsers that don't support
selectedOptions
,Demo
Here is some full code for you to use...gotta love the Google AJAX API Playground :-)
Edit 1: Note: this only lets you choose 5 because I didn't feel like copy/pasting another 10 options :-)
Demo
Voila! No Jquery necessary.
Jilusan
Using jQuery you can attach a function to the change event and since it is a multiple select the val() will be an array. You can always check the length of the array and do something if its a predefined size. The following code demonstrates how you will know how many items are selected.
I basically merged a couple of the provided answers to make something specific to a particular ID:
Rob