Reputation: 27
I want to call two javascript functions, for this i am using
<input type="submit" values="submit" onclick="return mandatoryCheck(); submitScore();">
But submitScore()
function didn't execute.
Need help...
Upvotes: 0
Views: 780
Reputation: 1147
I had a similar problem, selectJQgridRow()
was not working. My input was like:
<input type="button" values="Check" onclick="mandatoryCheck(); selectJQgridRow();">
The JavaScript functions were in a separated JavaScript file.
The problem was in the functions definition time.
I had to create selectJQgridRow()
after the jQgrid table definition. I just put it the last and done.
Upvotes: 0
Reputation:
Using return
inside of a function (in this case, the onclick is a function) will essential "stop" anything past the return statement to happen.
For instance:
var example = function(){
return true;
console.log("Hello.")
}
That will never log because the function returned a value before the other console.log()
function could be reached...
That being said, you should redesign your function like this:
onclick="mandatoryCheck(); submitScore();"
Upvotes: 0
Reputation: 133403
Assuming your are performing some validation check in mandatoryCheck()
and its returning true/false
. You should use &&
operator
Use
<input type="submit" values="submit" onclick="return mandatoryCheck() && submitScore();">
Upvotes: 1
Reputation: 4221
Add semi-colons ; to the end of the function calls in order for them both to work.
<input type="submit" values="submit" onclick="mandatoryCheck(); submitScore();">
Here is a good reference from SitePoint http://reference.sitepoint.com/html/event-attributes/onclick
Upvotes: 0
Reputation: 216
The 2nd function is unreachable because of the return.
<input type="submit" values="submit" onclick="mandatoryCheck(); submitScore();">
Upvotes: 0