Onsubmit event, silently killed onchange

An Onsubmit event can silently kill an onchange event if it is called at the same time. I guess the race condition in the js engine. Tested in Chrome, FF3, FF6 and IE9.

To play, you need to change the contents of the input and press the submit button. Do not make any extra clicks between changing the input and pressing the submit button.

<div id="somediv">
    <div>one</div>
    <div>two</div>
</div>
<form method="POST" id="someform">
    <input type="text" name="input1" id="someinput" value="change me" />         
    <input type="submit" />
</form>
<script type="text/javascript">
    document.getElementById('someinput').onchange = function() {
        //some delay - DOM operations, AJAX or alert:
        document.getElementById('somediv').getElementsByTagName('div')[1].style.display = 'none';
        //or alert('123');
    }
    document.getElementById('someform').onsubmit = function() {
        alert('This event is not called');
    }
</script>

Expected Behavior: onchange event than onsubmit.

If we use the button instead of sending and triggering events one by one, everything works as expected.

If there are no operations in the onchange event (no delay), it works as expected.

If onchange changes the color of the div (doesn't display) - sometimes (3/10) works, as expected, lol.

js guru, please explain what the hell is going on?

+3
2

onsubmit onclick, onmousedown onmouseup . (, ) onmouseown, onmouseup , , . somediv .

+3

, , JS- : Javascript onchange onsubmit HTML?

, () - () - , onsubmit . , JS (). , () confirm() .

, , alert() confirm() onchange, ​​ .

+3

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


All Articles