I have the this form:
<form action="/web/events/add" id="EventAddForm" method="post" accept-charset="utf-8">
<div style="display:none;"><input type="hidden" name="_method" value="POST"/></div>
<div class="input text">
<label for="AddressSearch">Search address</label>
<input name="adress_search" type="text" id="AddressSearch"/>
</div>
<div class="input text required">
<label for="EventAddress">Address</label>
<input name="data[Event][address]" type="text" id="EventAddress"/>
</div>
<div class="input text required">
<label for="EventPostNr">Post nr</label>
<input name="data[Event][post_nr]" type="text" id="EventPostNr"/>
</div>
<div class="input text required">
<label for="EventCity">City</label>
<input name="data[Event][city]" type="text" id="EventCity"/>
</div>
<div class="submit">
<input onclick="disableSubmit(this)" type="submit" value="Save"/>
</div>
</form>
And so there is the disableSubmit
function which does not allow the form to be submited twice.
function disableSubmit(b)
{
b.disabled = true;
b.value = 'Saving...';
b.form.submit();
}
which is being called and there is no problem, but I would like to include the other function which would not allow the form to be submitted if some of the fields are in focus or enter key is pressed. Here it is:
$("#EventAddForm").submit(function( event ) {
if ( $("#AddressSearch").is(":focus") ||
$("#EventPostNr").is(":focus") ||
$("#EventCity").is(":focus") ||
event.which == 13){
event.preventDefault();
}
});
It used to work before I have introduced the disableSubmit
function, and what I need right now is to get both of the called, but just cannot figure it out.
Any help or guidance is much appreciated.