Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  57] [ 4]  / answers: 1 / hits: 118791  / 15 Years ago, wed, march 10, 2010, 12:00:00

How to call multiple functions on button click event?



Here is my button,



<asp:LinkButton
ID=LbSearch
runat=server
CssClass=regular
onclick=LbSearch_Click
OnClientClick=return validateView();ShowDiv1();>


But my ShowDiv1 doesn't get called...



My JavaScript functions:



function ShowDiv1() {
document.getElementById(ReportDiv).style.display = 'block';
return false;
}

function validateView() {

if (document.getElementById(ctl00_ContentPlaceHolder1_DLCategory).selectedIndex == 0) {
document.getElementById(ctl00_ContentPlaceHolder1_ErrorMsg).innerHTML = Please Select Your Category;
document.getElementById(ctl00_ContentPlaceHolder1_DLCategory).focus();
return false;
}
if (document.getElementById(ctl00_ContentPlaceHolder1_DLEmpName).selectedIndex == 0) {
document.getElementById(ctl00_ContentPlaceHolder1_ErrorMsg).innerHTML = Please Select Your Employee Name;
document.getElementById(ctl00_ContentPlaceHolder1_DLEmpName).focus();
return false;
}
return true;
}


If the ValidateView() function returns true I should call ShowDiv1().


More From » function

 Answers
9

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 taste
function clicked() {
var b = validateView();
if (b)
ShowDiv1()
return b;
}


and then



OnClientClick=return clicked();

[#97380] Friday, March 5, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
devlin questions
Tue, Apr 27, 21, 00:00, 3 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
Fri, Aug 28, 20, 00:00, 4 Years ago
;