0

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 ?

asked Oct 1, 2013 at 19:43

2 Answers 2

4

Try this:

 <button type="submit" 
 onClick="return formhash_register(this.form);">Submit</button>
answered Oct 1, 2013 at 19:45
Sign up to request clarification or add additional context in comments.

1 Comment

Just have in mind that javascript can be disabled, so preventing submission is not 100% bulletproof. Always validate user input on server too.
0

Change type to "button" which shouldn't automatically submit this form.

<button type="submit" onClick="formhash_register(this.form);">Submit</button>
answered Oct 1, 2013 at 19:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.