Manual event does not work

In the element $('input.filename').bind('change', function(){...}) there is a text element with a change event, and a pop-up window appears that fires this event using $('input.filename').trigger('onchange')|.change() .

Exception: if the change event is associated with the launch of the "onchange" attribute!

The attachment code looks like:

 input.change(function () { var dims = { 'width': settings.previewWidth, 'height': settings.previewHeight }; updateImagePreview(input, preview, dims); }); 

The startup code looks like this:

 var input = $("input[name='any_name']", window.opener.document); input .val("<?=$choice ?>") .trigger("onchange"); window.close(); 
+4
source share
2 answers

I don't fully understand the context, but the correct event to trigger is change , not onchange with jquery.

 input.trigger('change'); // not "onchange" 

or

 input.change(); 
+2
source

You should just do change () or trigger ("change"):

 var input = $("input[name='any_name']", window.opener.document); input .val("<?=$choice ?>") .trigger("change"); 

or more simply

 var input = $("input[name='any_name']", window.opener.document); input .val("<?=$choice ?>") .change(); 

If you use jQuery <1.4, the event will not bubble in Internet Explorer

0
source

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


All Articles