Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to determine if an HTML select is currently open?

Tags:

html

jquery

ajax

I have a page that is doing a continuous ajax refresh, and I don't want to do this refresh if the user is currently making a selection in a dropdown. Is there any way to check if the user has the dropdown opened, and then stop the update?

Thanks!

like image 426
Shane Fulmer Avatar asked Nov 06 '09 21:11

Shane Fulmer


People also ask

How do you check if an element is selected in HTML?

Use the tagName property to check if an element is a select dropdown, e.g. if (select. tagName === 'SELECT') {} .

How do I know if select2 is open?

select2:open is fired whenever the dropdown is opened. select2:opening is fired before this and can be prevented. select2:close is fired whenever the dropdown is closed. select2:closing is fired before this and can be prevented.

What is selectedIndex?

selectedIndex is a long that reflects the index of the first or last selected <option> element, depending on the value of multiple . The value -1 indicates that no element is selected.

How does HTML select work?

Definition and Usage. The <select> element is used to create a drop-down list. The <select> element is most often used in a form, to collect user input. The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the drop-down list will be submitted) ...


Video Answer


1 Answers

The only way I can think of, is to use a flag (a variable) that will change value when the user clicks the SELECT (and knowing that when the page is first loaded, the SELECT is closed) this should make it easy to know if the SELECT is open or not.

like image 82
Soufiane Hassou Avatar answered Oct 21 '22 22:10

Soufiane Hassou