Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put an onclick and a return false statement in the same submit button?

From what I understand, the default treatment for return false is:

<input type="submit" onclick="return false" />

However in my code I would like to have a submit button run a separate js function onclick which will give ajax output based on which radio button the user selected.

But since I'm using ajax and my js function to take care of the output, I want the submit button to return false.

But if I am already using onclick to point to the function:

<input type="submit" onclick="jsfunction()" />

where do I put return false?

Can I have 2 onclick statements?

The other option I would imagine is that if I know I am not going to be submitting the form regardless of which value the function returns, that it shouldn't be a submit button at all?

But if that's the case, is there a button I can code in html that looks the same as submit but doesn't have the submit property?

like image 419
user1299028 Avatar asked Oct 25 '12 08:10

user1299028


1 Answers

try to add your method (jsmethod) to your form onsubmit handler like this

<form onsubmit="jsfunction(); return false;">

and remove the input onclick handler.

like image 165
silly Avatar answered Oct 25 '22 22:10

silly