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'm not going to be submitting the form regardless of which value the function returns, that it shouldnt 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 doesnt have the submit property?

Answers:

Answer

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

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

and remove the input onclick handler.

Answer

just do like this

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

change in function

function jsfunction()
{
  //you code 
  return false;
}

or just try if you dont want to change function

<input type="submit" onclick="jsfunction();return false;" />
Answer

Like this:

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

or just use a button intead of a submit button:

<input type="button" value="Submit" onclick="jsfunction();" />
Answer

No you cannot have 2 onclick declarations but you can call multiple functions in the same onclick like:

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

And in the other function you can have:

function anotherFunction(){
  return false;
}

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.