Javascript event to select an item

I am looking to find a Javascript event that I need to include in a jQuery .bind function so that the function fires when a selection is made from a <select> element.

I am currently using .bind('change',function() { ...}) , but I need the event to fire when the selected parameter is selected again.

Any suggestions?

+4
source share
7 answers

In any case, the change in the selection cells is unreliable. Read:

http://www.quirksmode.org/dom/events/change.html#t05

I would probably go for something to click on (but to be suspicious, someone (-> IE) is going to make your life difficult). Or create something yourself without a choice.

+2
source

I am currently doing this successfully, clearing the dropdown list so that it can be re-selected. This will allow you to call the function again, adding it to your function to the end:

$('select option:selected').removeAttr('selected');

+4
source

It is possible, however, it is not fully supported. Here is an example:

HTML

 <select id="selectId"> <option value="1">A</option> <option value="2">B</option> <option value="3">C</option> <option value="4">D</option> </select> 

JQuery

 $("#selectId>option").click(function(){ alert(this.value); }); 

here is a mediocre approach to processing, i.e.:

 <div id="dropdownWrapper"> <select id="selectId"> <option value="1">A</option> <option value="2">B</option> <option value="3">C</option> <option value="4">D</option> </select> </div> 

Js

 var clickCount_guid324fF = 0; $("#dropdownWrapper").click(function(){ if(++clickCount_guid324fF % 2 == 0){ alert($("#selectId").val()); clickCount_guid324fF = 0; } }); 
+2
source

Wouldn't you press a button? .bind('click',function() { ...})

0
source

I did this with mouseup and checked where the event came from. If it was an option element, I processed select. No onchange listening onchange all:

 <body> <select id="select0"> <option value="0">option 0</option> <option value="1">option 1</option> <option value="2">option 2</option> </select> <script type="text/javascript"> $('#select0').bind('mouseup', function (e) { var src = e.target; if (src.nodeName.toLowerCase()==='option') { doMagicOnSelect(this); } }); function doMagicOnSelect(selectElem) { console.log('current value:'+selectElem.value); } </script> </body> 
0
source

There is no reliable event if the selected option is re-selected.

While on some browsers you can capture events originating from <option> (which you could use to catch clicks and keyboard events if you had the patience to try to reproduce the browser selection processing), this is non-standard and does not work in IE (because it uses native Windows widgets to implement select blocks that don't give such granular access).

If you need to restart the event when the same parameter is selected again, what you actually have does not look like a selection window for me; it might be better to replace it with a scripted popup div full of buttons. (There are many scripts that will replace the select box for the script div to give you more control over browsers where JavaScript is available.)

0
source

bind change and click event

 $select.bind("change click", function (event) { // do something }); 
0
source

Source: https://habr.com/ru/post/1306056/


All Articles