Reputation: 2214
I have this problem:
my HTML code:
<form name="addUser" method="post" action="../src/process_register.php">
....
<button type="submit" onClick="formhash_register(this.form);">Submit</button>
</form>
my JavaScript code:
function formhash_register(form)
{
var username = form.inputUsername.value;
if(username == "")
return false;
else
form.submit();
}
Although my function returns false, you will go to another page, and thats not what I wanted. Is there way to cancel submit process when the submit button is pressed ?
Upvotes: 0
Views: 5212
Reputation: 529
Change type to "button" which shouldn't automatically submit this form.
<button type="submit" onClick="formhash_register(this.form);">Submit</button>
Upvotes: 0
Reputation: 15115
Try this:
<button type="submit"
onClick="return formhash_register(this.form);">Submit</button>
Upvotes: 4