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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Nested Javascript

    Hello. I was wondering if there is a way to call a second Javascript function from within the first. For example:

    <script>...call first function...</script>

    Inside first function:

    If (a==1)
    <script>...call second function...</script>
    else (a==2)
    <script>...call third function...</script>

    My thinking as to why I would need this is because I need to access two different Google Maps API codes.

    If that isn't possible, does anyone have any other suggestions?

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,425
    Thanks
    17
    Thanked 272 Times in 272 Posts
    If you have linked to the scripts on your page you don't need the inner script tags, just call the function, make sure that the links are before the functions are called and that you pass it the correct arguments.
    Code:
    If (a==1)
    
        doThis(args):
    
    else (a==2)
    
        doThat(args);
    That's all you need to do.

  • Users who have thanked DrDOS for this post:

    worldtravlur (09-21-2010)

  • #3
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you DrDOS. That helps a lot!

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,238
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Quote Originally Posted by DrDOS View Post
    Code:
    If (a==1)
    Javascript is case sensitive. If != if.

    DrDOS - I think it would be a good idea if you only answered forum questions within your ability range.

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,425
    Thanks
    17
    Thanked 272 Times in 272 Posts
    Quote Originally Posted by Philip M View Post
    Javascript is case sensitive. If != if.

    DrDOS - I think it would be a good idea if you only answered forum questions within your ability range.
    I just copied and pasted his code, and missed the fact that he capped the if. sorry about that.


  •  

    Posting Permissions

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