Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent the dropdown from opening in a DropDownList?

I have a custom table which I'd like to use as the DropDown portion as a DropDownList.

Table

Ideally, when users click on a DropDownList, it should show the custom table instead of the usual drop down. I thought it'd be easy to prevent the dropdown from opening without disabling the DropDownList control, however that doesn't appear to be the case.

Is there an easy way to prevent a DropDownList from opening without disabling it?

Edit: This has to work for an embedded IE 7 web browser, and e.preventDefault() does not work in that browser version

like image 462
Rachel Avatar asked May 31 '12 19:05

Rachel


People also ask

How do I stop dropdown menu from pushing content down?

Make your dropdown menu's position: absolute; and then the element under it as position: relative; . If this doesn't work, try to make both the dropdown menu and the element under it as position: absolute; and then set the z-index of the dropdown as higher than the element below it.

How do I turn off select option in dropdown?

The drop-down is used to create a list of items that need to select an element. We use <select> and <option> elements to create a drop-down list and use disabled attribute in <select> element to disable the drop-down list element.

How do I make a dropdown readonly?

You need to add a "disabled" property to the form dropdown class.

How do you enable disable a dropdown based on value in another dropdown in JavaScript?

prop("disabled", true); } else $("#ddl2"). prop("disabled", false); }); }); The above code will disable the "ddl2" dropdown on select of a particular value in first dropdown. And will enable it if you select another value.


1 Answers

You can do something like this:

Basically, I have positioned an invisible div over the dropdown to block it, and you can handle the click with the onclick of the masking div.

EDIT: I have updated this http://jsfiddle.net/EdM7B/1/

<div id='mask' onclick='alert("clicked");' style='width:200px; height:20px; position:absolute; background:white;filter:alpha(opacity=0);'></div>
<select id='selectList' show=1 style='width:200px; height:20px;'>
    <option>Test</option>
</select>

I had to use a sort of hack because IE doesn't seem to render divs properly that have no background colour set, so it wasn't working correctly. This works in my IE7.

If you want it to work in all browsers you'll need to add chrome/firefox opacity CSS or have some IE only CSS to apply background colour.

I think due to the way it's positioned above, the opacity is actually not working properly because the element is positioned absolutely, either way it seems to work. I originally had it as opacity 1, but that sounds wrong to me as we want it invisible, so I changed it to 0.

like image 88
NibblyPig Avatar answered Oct 24 '22 11:10

NibblyPig