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
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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.