Calling Multiple Javascript Functions On A Button Click
How to call multiple functions on button click event? Here is my button,
Solution 1:
Because you're returning from the first method call, the second doesn't execute.
Try something like
OnClientClick="var b = validateView();ShowDiv1(); return b"
or reverse the situation,
OnClientClick="ShowDiv1();return validateView();"
or if there is a dependency of div1 on the validation routine.
OnClientClick="var b = validateView(); if (b) ShowDiv1(); return b"
What might be best is to encapsulate multiple inline statements into a mini function like so, to simplify the call:
// change logic to suit tastefunction clicked() {
var b = validateView();
if (b)
ShowDiv1()
return b;
}
and then
OnClientClick="return clicked();"
Solution 2:
That's because, it gets returned after validateView();;
Use this:
OnClientClick="var ret = validateView();ShowDiv1(); return ret;"
Solution 3:
Try this .... I got it... onClientClick="var b=validateView();if(b) var b=ShowDiv1();return b;"
Solution 4:
Change
OnClientClick="return validateView();ShowDiv1();">
to
OnClientClick="javascript: if(validateView()) ShowDiv1();">
Solution 5:
It isn't getting called because you have a return statement above it. In the following code:
function test(){
return 1;
doStuff();
}
doStuff() will never be called. What I would suggest is writing a wrapper function
function wrapper(){
if (validateView()){
showDiv();
return true;
}
}
and then call the wrapper function from your onclick
handler.
Post a Comment for "Calling Multiple Javascript Functions On A Button Click"