Suppose that I've this:
<form onsubmit="Popup(this)">
when I press the submit
button the Popup
function is fired. How can I get the submit
event and prevent it?
Popup: function(item)
Thanks.
try this:
function( item ) {
alert( "Handler for .submit() called." );
item.preventDefault();
// rest of the code
}
OR
$("#form_id").validate({
submitHandler: function (form) {
// do code
return false;
}})
Since you tagged your question with jQuery.
$('form').submit(Popup); //this inside the function is the form.
// The first parameter is the event.
And make sure to return false from Popup
If Popup
isn't a constructor, use camelCase naming
Your existing code should work if you just modify it just a bit. Add return
to your Popup
method call
<form onsubmit="return Popup(this)">
And at the end of your method declaration add return false
Popup: function(item){
// your code goes here
return false; //add this
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.