Sometimes you don't need users to select some of the options in the HTML drop down menu.
For example you have a dropdown menu with these options.
==========================
Please select a province/state for US/Canada
Canada
--------------
Prov1
...
Prov10
United States
--------------
State1
...
State50
==========================
What we need is a province/state but what if the user selects the separators '----' ? or the country name ?
To solve this challenge we use negative values for values that should not be selected. Then using jQuery we disable them.
[code language="jscript"]
[/code]
Related:
- http://jivebay.com/2007/05/30/handling-checkboxes-radio-buttons-and-select-options-in-jquery/
- http://techeyes.blogspot.com/2007/11/making-html-select-readonly.html
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer
Thanks for the pointers! With the latest jQuery you need to do it this way to loop the select:
$("#my_select_id option").each(function (index, obj) {});
thanks for the comment!