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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling TWO OnClick functions

    I just finished putting javascript code into my web page, a pretty simple routine that changes the link color on mouseover, changes it again on mouseout, and launches a hyperlink onclick.

    I'd like to add something. So that onclick, it plays a sound and also launches the hyperlink.

    I've seen some javascript for playing an onclick sound, not sure what's best. but right now my main question is how to write the line so that OnClick does TWO things.

    (also - small side question - can the sound be .wav or .aif, or does it have to be .au? what's best? it's a tiny sound - about 1/2 a second long.)

    THANK YOU!

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,504
    Thanks
    3
    Thanked 501 Times in 488 Posts
    onclick="Function1();Function2();"

  • #3
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    onclick calls any valid javascript code. So you can use a function and/or just separate lines of code with semi-colons. I prefer functions to a ton of embedded code. If I have more than a couple statements, I use functions.

    i.e.

    onClick="var x=0;alert(x);"

    or

    onClick="doFunction1(); doFunction2();"

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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