Reputation: 463
I have a text field in a form that is set to type="url"
. Before submitting Firefox seems to verify whether the URL is correct or not, if the URL is invalid it will not submit it. However, jQuery's function $("element").submit()
is run even if the form is not submitted. How can I avoid this?
My form is as following:
<form id="form-add-dataset" role="form" action="submit.php" enctype="multipart/form-data" method="POST" >
...
<input type="url" name="authors_website" class="form-control" autofocus>
...
<button id="upload-button" type="submit" class="btn btn-lg btn-primary"><span class="glyphicon glyphicon-upload"></span> Upload</button></div>
</form>
My jQuery code is as following:
$("#form-add-dataset").submit(function() {
//Do stuff
});
Thanks in advance!
Upvotes: 2
Views: 43
Reputation: 635
you can put your event on the <button id="upload-button" type="submit" class="btn btn-lg btn-primary"></buton>
and return the good value for submitting or not your form.
$('#upload-button').on('click', function(){
if(){ // test your params
return false; // here if you return false the form are not submit
}
return true; // but if you return true the form is submit
});
Upvotes: 1