HTML select element: how to simulate an onStayTheSame event?

For the select element, we have an onchange event. I want to call a function call if the user clicks on the drop-down list but then selects the same current option.

I wonder if anyone has tried this before, and what a reliable sequence of onclicks, onmouseups, etc. may look like.

thanks

+4
source share
1 answer

How about this ...

 var select = document.getElementById('your-element'), changed = false; select.onchange = function() { changed = true; console.log('Picked something new.'); } select.onfocus = function() { changed = false; } select.onblur = function() { if (!changed) { select.onStayTheSame.call(); } changed = false; } select.onStayTheSame = function() { console.log('Stayed the same.'); } 

Take a look at jsFiddle .

He has a few questions, but hopefully this is a good start :)

+4
source

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


All Articles