Jump to content

disable selct options


raman

Recommended Posts

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 ?

Link to comment
https://forums.phpfreaks.com/topic/179452-disable-selct-options/
Share on other sites

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!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.