Menu

#99 Form.onsubmit() not executing in Chrome, IE and Safari

open
nobody
None
5
2014-08-18
2011-09-16
No

This happens only when the submit button is disabled. I have a form with id "areaform" and onclick="alert('!')". Inside of the form there is a submit button with id "submitbutton and onclick=submitFotton()". So it looks like this:

<form onsubmit="alert('!')" id="areaform">
<textarea id="area" name="area"></textarea>
<input type="submit" id="submitbutton" onclick="buttonSubmit()"/>
</form>

This means that when user clicks submit, the buttonSubmit() should be called first and then it should alert.

However, my buttonSubmit function disables the submit button (to prevent the user from being able to submit the form twice), which prevents the alert. This is an expected behavior. Therefore, we are calling form.onsubmit() manually and then submitting form.submit() manually, like this:

function buttonSubmit()
{
document.getElementById('submitbutton').disabled=true;
var theForm = document.getElementById('areaform');
if (theForm.onsubmit)
theForm.onsubmit();
theForm.submit();
}

This works perfectly fine when edit_area_loader.js isn't imported: when user clicks submit button, the button gets disabled, form.onsubmit() is called (alert) and the form gets submitted.

However, when we import the edit_area_loader.js (without adding any additional code), then in Chrome when user clicks submit button, then the button still gets disabled, the form still gets submitted, but onsubmit() isn't called. Value of theForm.onsubmit is null and the call theForm.onsubmit() ends up with a javascript error.

This problem happens in Chrome only and it did not used to happen in previous version of EditArea we used. So it's happening in Edit area v0.8.2 but did not used to happen in v0.8.1.1

Discussion

  • Artur Tomusiak

    Artur Tomusiak - 2011-09-16

    Full example demonstrating the problem - try removing the line that imports edit_area_loader.js and see difference in execution in Chrome

     
  • Artur Tomusiak

    Artur Tomusiak - 2011-09-16
    • summary: Form.onsubmit() not executing in Chrome --> Form.onsubmit() not executing in Chrome, IE and Safari
     

Log in to post a comment.

MongoDB Logo MongoDB