views:

109

answers:

3

Hi, How can I activate/deactivate dropdown of classic selectbox by clicking to link in jQuery? I don't need selectbox replacing with jQuery, because it's too slow for huge number of options. I test everything but without result. Thanks

sample page http://www.jklir.net/test-selectbox.html

A: 

If you mean to enable/disable the dropdown when you click on the link, you could do this way:

$('a#link_id').toggle(function(){
  $('#dropdown_id').attr('disabled', 'disabled');
}, function(){
  $('#dropdown_id').removeAttr('disabled');
})

Where link_id is supposed to be the id of the link and dropdown_id is supposed to be the id of the select box. The toggle function will disable the select box on first click on the link and enable it back on second click and so on.

Sarfraz
I think he wants to disable a single `<option>`, but it's only a supposition as the question hasn't been clear enough.
Darin Dimitrov
@Darin Dimitrov: Yeah i posted what I have figured out but he needs to clarify that :)
Sarfraz
Right, for single <select> <option> dropdown
JKLIR
Here is the sample page http://www.jklir.net/test-selectbox.html
JKLIR
A: 

If you're saying that you want the <select> to display its options via javascript, I don't think it can be done cross-browser (or perhaps in any browser).

Is this what you meant?

If so, I think you'll be stuck creating your own, but finding some other way to accommodate the large quantity of options you require.

patrick dw
Yes, classic <select> with <option>.
JKLIR
@JKLIR - Please explain exactly what you want to accomplish, since your question is being interpreted a few different ways. Do you want the `<select>` to "pop up" and display its options? Or do you want to just select *one* option without popping up? What exactly do you mean?
patrick dw
Here is the sample page http://www.jklir.net/test-selectbox.html
JKLIR
@JKLIR - From your example it appears as though you are trying to *display* or *open* the `<select>` by triggering a `.click()`. Unfortunately, there is no way to do this with a classic select. See my answer above.
patrick dw
A: 
if ($(this).attr("disabled") == true) {
                if ($.browser.msie) {
                    $containerDivText.attr("disabled", $(this).attr("disabled"));
                    $newUl.attr("disabled", $(this).attr("disabled"));
                    $containerDiv.attr("disabled", $(this).attr("disabled"));
                }
                else {
                    $newUl.remove("li");
                    $containerDivText.unbind("click");                    
                }
            }

Mohan Prajapati