raman Posted October 29, 2009 Share Posted October 29, 2009 I have a drop-down menu in my front-end. <select name="aminoacid[]" size="4" multiple="multiple"><option value='all' style='color:#3300CC'>any</option><option value='C' style='color:#3300CC'>Cys</option><option value='D' style='color:#3300CC'>Asp</option><option value='E' style='color:#3300CC'>Glu</option> Now I want that if the user selects any, then all other options shouls be disabled with an onchange event whereas if the user selects any other option, then there should be no such change, he should still be able to selet other options. Can some one tell the javascript code for this ? Quote Link to comment Share on other sites More sharing options...
seanlim Posted October 29, 2009 Share Posted October 29, 2009 I don't think you can disable individual options. The most you could do is probably to prevent any further changes to the SELECT if "any" is selected. However, I think that such a design would leave your users puzzled: it is rather counter-intuitive as that is not how a SELECT combo box should work. A better option, IMO, is to provide a separate checkbox labelled "any". When selected, disable the SELECT. When unselected, re-enable the SELECT. Just my opinion though, as I can imagine myself struggling to select the options, only to realise that I have to unselect "any" first! Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 try readonly, or disabled, disabled will stop it being submitted, readonly may work on individual options, you need to e=document.getElementById('theselectboxid') on click for(i=0;i<e.select.options.length;i++){ e.select.options.[i].disabled or readonly = true; } i cant rembe rteh exact composition of teh select element as an array in javascript doc ob mod somthing like that, you can use firebug and in the commandline type in N=document.getElementById('theselectboxid') then you can look at the structure of the array the element is Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.