I want to execute a basic form message, but the following is sent to the server twice in Chrome and Safari (but behaves as expected in Firefox):
<form id="create-deck-form" action="/decks/create" method="post"> <fieldset> <legend>Create new deck</legend> <label for="deck-name-field">Name</label> <input id="deck-name-field" name="deck-name-field" type="text" value="" maxlength="140" /> <label for="tag-field">Tags</label> <input id="tag-field" name="tag-field" type="text" value="" maxlength="140" /> <input class="add-button" type="submit" value="Create" /> </fieldset> </form>
I would like to use the onsubmit attribute to do validation in the fields before submitting, but wherever the return value is true , the form is submitted twice.
I tried to associate the jQuery handler with the form, but here too, where the default behavior is not prevented, the form appears twice, for example:
<script type="text/javascript"> $(document).ready(function() { $("#create-deck-form").submit(function(event){ if($("#deck-name-field").val() == "") { event.preventDefault(); alert("deck name required"); } }); }); </script>
Although I believe that there is something dazzlingly obvious, I am deeply confused why submission with or without verification makes a duplicate message on the server in Chrome and Safari. I would be grateful for your understanding.
jquery cross-browser forms double-submit-problem facebox
meg
source share