I have html
form and when I clicked submit
button page goes to insert.php
I don't wont it
preventDefoult don't work
I have this script
html
HTML
<form action="insert.php" method="post">
<input type="text" name="username" placeholder=""><br />
<input type="text" name="name" placeholder=""><br />
<input type="text" name="lastname" placeholder=""><br />
<input id="mail" name="email" type="text" placeholder="E-mail"><br />
<input id="mail_1" type="text" placeholder="reply E-mail"><br />
<input id="password" name="password" type="password" placeholder=""><br />
<input id="password_1" type="password" placeholder=""><br />
<input id="submit" type="submit" value="registration">
</form>
jquery
$("#submit").click(function(event){
event.preventDefault();
});
We use the preventDefault() method with this event to prevent the default action of the form, that is prevent the form from submitting.
Definition and Usage. The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur. For example, this can be useful when: Clicking on a "Submit" button, prevent it from submitting a form.
preventDefault() The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.
Instead of listening for the button click you need to listen for <form>
submit:
$("form").submit(function(event){
event.preventDefault();
});
Modern jQuery (1.7 or later):
$("form").on('submit', function(event){
event.preventDefault();
});
I think you just missed the event which is canceling
$( "#target" ).submit(function( event ) {
event.preventDefault();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With