By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

Can OnClick call multiple functions?

LacrosseB0ss
100+
P: 113
I was wondering, can an OnClick event of a button call multiple functions?

The reason for this is I have a page that when "ok" is clicked, goes to a preview page before submitting data to the database. If "Modify" is clicked, I want to change session variables (using VB) and then go to the previous page (the easiest way I know how to do this is history.go(-1) in js).

Can OnClick call both functions? Or is there a way to do this in only VB or JS?

TIA
- LB
Nov 30 '06 #1
Share this Question
Share on Google+
13 Replies


Expert 100+
P: 1,892
I think the easiest way would be make 2 functions then a 3 that will decide which of the 2 it wants to call.
Nov 30 '06 #2

LacrosseB0ss
100+
P: 113
The reason I wanted to do it this way was because I want to use Javascript code as well as VB code. The VB will change session variables and the JS will change the page.

I have since tried using VB and in the Page_Load method saying
Expand|Select|Wrap|Line Numbers
  1. Dim prevPageURL As String = Page.PreviousPage.ToString
  2. cmdModifyForm.Attributes.Add("PostBackUrl", prevPageURL)
  3.  
and then doing the session variables in cmdModifyForm_Click. We'll see how that goes.

Thanks again
- LB
Nov 30 '06 #3

100+
P: 143
You can just call a single function with the onclick, then this will call 2 other function.

Expand|Select|Wrap|Line Numbers
  1. <button onclick="javascript: funcCaller();" value="press me" />
  2.  
  3. <script type="text/javascript">
  4.  
  5. function funcCaller() {
  6.   funcOne();
  7.   funcTwo();
  8. }
  9.  
  10. ...
  11.  
  12. </script>
Dec 1 '06 #4

P: 3
Above code simply call 2 functions at the same time. I just want to know how to call functions like ELSE IF . if 1 function check finished , another to call


regards
Feb 26 '07 #5

iam_clint
Expert 100+
P: 1,208
<input type="button" onclick="function1(); function2(); function3(); function4(); function5();">
Feb 26 '07 #6

P: 3
i mean it's run all functions at the same time. i just want to run 1st function first. if the 1st function is OK, the second function to work.

Example is that ----
__________________________________________________ _______________
function formcheck(){
if (usr==""){
alert ("Please provide User Name");
frm.usrid.focus();
}
}

function numcheck(){

var NumExpression=/^[0-9]+$/;
if (!document.frm.scode.value.match(NumExpression)){
alert("Invalid, Number Only");
frm.scode.select();
return false;
}

}

<input type="button" value="submit" onclick ="formcheck(); numcheck();">
__________________________________________________ ______________

so if i write like above state, it run all the alert messages. i just want to run formcheck() function first. if it is OK and no more blank " " in Text box , User will click Submit button, then the second numcheck() function will work.
I don't want to put 2 Submit button. That's the problem.
so~~~

How can i call function correctly ? Any1 please
Feb 26 '07 #7

Expert 100+
P: 1,892
i mean it's run all functions at the same time. i just want to run 1st function first. if the 1st function is OK, the second function to work.

Example is that ----
__________________________________________________ _______________
function formcheck(){
if (usr==""){
alert ("Please provide User Name");
frm.usrid.focus();
}
}

function numcheck(){

var NumExpression=/^[0-9]+$/;
if (!document.frm.scode.value.match(NumExpression)){
alert("Invalid, Number Only");
frm.scode.select();
return false;
}

}

<input type="button" value="submit" onclick ="formcheck(); numcheck();">
__________________________________________________ ______________

so if i write like above state, it run all the alert messages. i just want to run formcheck() function first. if it is OK and no more blank " " in Text box , User will click Submit button, then the second numcheck() function will work.
I don't want to put 2 Submit button. That's the problem.
so~~~

How can i call function correctly ? Any1 please
Add a boolean var blnIsValid = true then set it to false anytime something doesn't go right at the end check that the variable is true if so go to function 2 if not go back to function 1.
Feb 26 '07 #8

P: 3
Add a boolean var blnIsValid = true then set it to false anytime something doesn't go right at the end check that the variable is true if so go to function 2 if not go back to function 1.

Please show me example codes or program...
Feb 28 '07 #9

acoder
Expert Mod 15k+
P: 16,027
Please show me example codes or program...
I assume you want something that shows an alert if there is a problem by going through the functions. You don't need the user to press the submit button again if the first validation passed.

Just include all your functions in one formCheck function. Then this function can call all the functions one by one. Whenever a function 'fails' (meaning there is an error), just return false, otherwise it continues on till the end:
Expand|Select|Wrap|Line Numbers
  1. function formCheck {
  2. if (!numCheck()) return false;
  3. if (!emailCheck()) return false;
  4. ...
  5. }
is one way. There are other ways. For an example, see this. For a different style of form validation, see this link.
Feb 28 '07 #10

P: 52
i want to call
onClick="document.pressed=this.value"
and
onClick="return validate();
what do i write ?
Mar 27 '09 #11

gits
Expert Mod 5K+
P: 5,333
just wrap both calls in one function and call that function on click ... or write both of the statements separated with a semicolon in one place ...
Mar 27 '09 #12

P: 1
if there are many validations,then will you be using multiple functions??
Aug 16 '11 #13

P: 1
Expand|Select|Wrap|Line Numbers
  1. function Validation3() {
  2.      if(Validation1() !=false)
  3.      {
  4.          Validation2(); 
  5.      }
  6. }
  7.  
  8. <input type="submit" onclick="return Validation3()"/>
In the first function you have return a Boolean value. Suppose you want call second function only if the first function returns true. you can use the above code. so with out the success of first function you can't call second function
Feb 16 '15 #14

Post your reply

Sign in to post your reply or Sign up for a free account.