1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

JS help/question

Discussion in 'Other Languages' started by Bryan, Sep 8, 2010.

  1. Bryan

    Bryan Power Member

    Joined:
    Aug 25, 2009
    Messages:
    565
    Likes Received:
    292
    is there a way where I can run a .js file after a click?

    like if I have a js file called x.js and it has alert code

    and I have a button, I want it to pop up the alert after they click the button

    hope this makes sense, let me know if it's possible, thanks!
     
  2. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    Two ways:

    1)Include dynamically your "x.js" file
    2)Include normal your "x.js" file, add to it some function and call this function
     
  3. paincake

    paincake Power Member

    Joined:
    Aug 18, 2010
    Messages:
    716
    Likes Received:
    3,099
    Home Page:
    Code:
    <button onclick="alert('woohoo!');">click me</button>
    or include the js file at the beginning with <script> tag and then just use a variable from there
    Code:
    <button onclick="alert(variable_name);">click me</button>