Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    357
    Thanks
    23
    Thanked 1 Time in 1 Post

    Function trigger function

    how would you make a function trigger a other function?

  • #2
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    can you explain what you mean a little more please?

  • #3
    Regular Coder
    Join Date
    May 2011
    Posts
    357
    Thanks
    23
    Thanked 1 Time in 1 Post
    Quote Originally Posted by nomanic View Post
    can you explain what you mean a little more please?
    a function that when set off triggerd a other function?

  • #4
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    like this?

    Code:
    function a() {
      alert('function a called');
    }
    
    function b() {
       //Some stuff in here
       //then trigger function a
       a();
    }
    
    b();

  • #5
    Regular Coder
    Join Date
    May 2011
    Posts
    357
    Thanks
    23
    Thanked 1 Time in 1 Post
    Quote Originally Posted by nomanic View Post
    like this?

    Code:
    function a() {
      alert('function a called');
    }
    
    function b() {
       //Some stuff in here
       //then trigger function a
       a();
    }
    
    b();
    Could you explain how the trigger function works?

  • #6
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    im sorry i really dont know what youre asking, you want function b to call function a right?

  • #7
    Regular Coder
    Join Date
    May 2011
    Posts
    357
    Thanks
    23
    Thanked 1 Time in 1 Post
    Quote Originally Posted by nomanic View Post
    im sorry i really dont know what youre asking, you want function b to call function a right?
    Ya what i men is you put "//then trigger functin a" so how do a trigger a?

  • #8
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts
    Hello sherlockturtle!

    nomanic's example does what you want, but let's run through a quick example for further proof.

    Suppose you have this function:
    Code:
    function AlertOne(){
        alert(1);
    }
    Any time the AlertOne function is called, like this:
    Code:
    AlertOne();
    It will be executed and you will of course get a popup (a.k.a., an alert) with the number 1 in it.

    So suppose you also have this function:
    Code:
    function AlertTwo(){
        alert(2);
    }
    Similarly, when the function is called using AlertTwo();, it will alert the number 2 just as it says within the function's brackets.

    Finally, suppose you have this function:
    Code:
    function AlertOneAndTwo(){
        AlertOne();
        AlertTwo();
    }
    Whenever the AlertOneAndTwo function is called, like this:
    Code:
    AlertOneAndTwo();
    AlertOne(); and AlertTwo(); will run as they are between the AlertOneAndTwo functions brackets... and so you'll see an alert with 1 and then an alert with 2.
    I'm the founder of Loggur, a place to build and share web apps focused on maximizing efficiency and productivity:
    http://www.loggur.com

    My personal site and blog:
    http://www.tfburgess.com

  • #9
    Regular Coder
    Join Date
    May 2011
    Posts
    357
    Thanks
    23
    Thanked 1 Time in 1 Post
    Quote Originally Posted by tfburges View Post
    Hello sherlockturtle!

    nomanic's example does what you want, but let's run through a quick example for further proof.

    Suppose you have this function:
    Code:
    function AlertOne(){
        alert(1);
    }
    Any time the AlertOne function is called, like this:
    Code:
    AlertOne();
    It will be executed and you will of course get a popup (a.k.a., an alert) with the number 1 in it.

    So suppose you also have this function:
    Code:
    function AlertTwo(){
        alert(2);
    }
    Similarly, when the function is called using AlertTwo();, it will alert the number 2 just as it says within the function's brackets.

    Finally, suppose you have this function:
    Code:
    function AlertOneAndTwo(){
        AlertOne();
        AlertTwo();
    }
    Whenever the AlertOneAndTwo function is called, like this:
    Code:
    AlertOneAndTwo();
    AlertOne(); and AlertTwo(); will run as they are between the AlertOneAndTwo functions brackets... and so you'll see an alert with 1 and then an alert with 2.
    Ive tried that it does not work.

  • #10
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts
    May I see your code?

    If you're using Internet Explorer, a yellow bar may appear at the top of the page asking if you want to allow javascript and you'll need to allow it of course if you want it to work.
    Last edited by tfburges; 07-28-2011 at 05:52 AM.
    I'm the founder of Loggur, a place to build and share web apps focused on maximizing efficiency and productivity:
    http://www.loggur.com

    My personal site and blog:
    http://www.tfburgess.com

  • #11
    Regular Coder
    Join Date
    May 2011
    Posts
    357
    Thanks
    23
    Thanked 1 Time in 1 Post
    Quote Originally Posted by tfburges View Post
    May I see your code?

    If you're using Internet Explorer, a yellow bar may appear at the top of the page asking if you want to allow javascript and you'll need to allow it of course if you want it to work.
    Im using chrome ill post my code in a little while i goto go so bye.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •