How to call multiple functions on button click event?
Here is my button,
Change
OnClientClick="return validateView();ShowDiv1();">
to
OnClientClick="javascript: if(validateView()) ShowDiv1();">
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.
<asp:Button ID="btnSubmit" runat="server" OnClientClick ="showDiv()"
OnClick="btnImport_Click" Text="Upload" ></asp:Button>
I think that since return validateView();
will return a value (to the click event?), your second call ShowDiv1();
will not get called.
You can always wrap multiple function calls in another function, i.e.
<asp:LinkButton OnClientClick="return display();"> function display() { if(validateView() && ShowDiv1()) return true; }
You also might try:
<asp:LinkButton OnClientClick="return (validateView() && ShowDiv1());">
Though I have no idea if that would throw an exception.
At times it gives syntax error that "return is not a function" so in that case just remove return and it will work fine :) as shown below
OnClientClick="var b = validateView(); if(b) var b = ShowDiv1(); b;"
btnSAVE.Attributes.Add("OnClick", "var b = DropDownValidate('" + drp_compcode.ClientID + "') ;if (b) b=DropDownValidate('" + drp_divcode.ClientID + "');return b");