dimanche 12 avril 2015

Catch form submit event in JavaScript / jQuery

I'm trying to catch a submit request for a form



<form action='/post' name='submitform' id="submitform" method='post' class='pure-form'>
<textarea columns="40" rows="4" name='entry[body]' id="statement"></textarea>
<input type='submit' id="submitbutton" name="btnSubmit" value="save" class="pure-button pure-button-primary">
</form>


using



document.querySelector('#submitform').addEventListener('submit', function(e) { /* code */ });


which works fine if I click a submit button


but when I call



$('#submitform').submit();


or



document.forms["submitform"].submit();


the form submits bypassing my event listener.


Why?


Aucun commentaire:

Enregistrer un commentaire