How to make the select.change event not fire until it loses focus (preferably using jquery)?

I have a select box using the jQuery dropdownchecklist plugin. I want the fire of the change event to occur only after the selection field loses focus.

The jquery.change event is fired to select blocks immediately after selecting an item in the list. In my case, since several elements can be selected, I want the changes to light up after the focus is lost, provided that the new elements have even been selected.

I thought I could make some kind of chain like $ ('# MySelect'). change (). blur (...) or some kind of nesting or something like that, but I could not get it to work as I would expect.

Any ideas?

+4
source share
3 answers

Perhaps you just want to provide a blur event handler and ignore the change event altogether. Then you will have to track the changes yourself. One suggestion is that the change event simply updates the variable, which tells you that the changes occurred without any other action. Then the blur event can do this:

$('#yourselect').blur(function(){ if(changesOccurred){ //do something about it changeOccurred = false; } }); $('#yourselect').change(function(){ changeOccurred = true; }); 
+3
source

You have to do it.

 $('select').focus(function() { $(this).data( 'startValue', $(this).val() ); } $('select').change(function(event) { event.preventDefault(); }); $('select').blur(function() { if ( $(this).data('startValue') == $(this).val() ) { //nothing has changed } else { //something different } } 
+1
source

Well, the change event is fired when the drop-down list changes. You cannot change this (what a ridiculous sentence in this context).
You must configure your code so that all of your functions that were normally executed on change are executed in the blur event.

Update: If you provided some code and an explanation of what should have been done, then it would be easier for you to help.

0
source

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


All Articles