473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can OnClick call multiple functions?

LacrosseB0ss
113 100+
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
13 107446
AricC
1,892 Expert 1GB
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
113 100+
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
steven
143 100+
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
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
1,208 Expert 1GB
<input type="button" onclick="function1(); function2(); function3(); function4(); function5();">
Feb 26 '07 #6
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
AricC
1,892 Expert 1GB
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
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
16,027 Expert Mod 8TB
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
i want to call
onClick="document.pressed=this.value"
and
onClick="return validate();
what do i write ?
Mar 27 '09 #11
gits
5,390 Expert Mod 4TB
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
if there are many validations,then will you be using multiple functions??
Aug 16 '11 #13
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

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

Similar topics

10
by: reynoldscraigr | last post by:
Hi All, I am trying to call 2 functions from the 1 onMouseOver event on an anchor tag, but I can't seem to get it to work. the following should demonstrate <a...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
2
by: Wei Wang | last post by:
Hi, Can I call multiple functions in one trigger? Something like this: CREATE TRIGGER match_cond_name_generate BEFORE INSERT OR UPDATE ON public.predicate_index FOR EACH ROW EXECUTE...
7
by: pronerd | last post by:
Does any one know how to add a function to an event handler with out losing the current event handler? For example you can add multiple functions to a single event handler with something like : ...
2
by: dnewton | last post by:
Hi, Can the onlclick event call multiple functions Using ASP.NET I have created an image button that runs my form at server side and makes use of an onClick event... but... I would also...
3
by: deepthisoft | last post by:
hai, I have 2 javascript funtions.I want to call these 2 functions using one button. my code is like this, <input type="button" value="ok" onclick="validate(this),change()">
3
by: grezly | last post by:
I have a link in my webpage, that wants to call to functions at once. <td onclick="createform(event,<?php echo $startdag;?>,<?php echo $maand;?>,<?php echo $jaar;?>);createpic(event,<?php echo...
1
by: su817200 | last post by:
Dear Friend, I would like to run multiple functions on Button Click eg... <input type="button" value="Update" name="B1" onclick="ReadFileToString() timedRefresh(1500)"></p> It is giving...
3
by: cheenna | last post by:
<script language="javascript"> var numLinesAdded = 0; var numLinesRemove = 0; function generateRow(){ var d = document.getElementById("div"); var newDiv =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.