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

    Post [request] javascript

    Hello. I need code.

    I want, on the website, with mouse one click (or on the button click), run my Javascript. Example this: goo.gl/2Ke9v9

    Can anyone help me?

    Respect from GEORGIA! (and sorry for my bad english)

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,159
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Code:
    <input type = "button" value = "Click me to run a script" onclick = "myJavascriptFunction()">
    Quote Originally Posted by R00TBL4CK View Post
    Respect from GEORGIA! (and sorry for my bad english)
    As Tom Lehrer said, "He's from Georgia and he doesn't speak the language very well".

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 08-26-2014 at 07:32 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    Yeah, Philip, but did you look at the URL he posted? It just links to
    http://pastebin.com/raw.php?i=iE3rdk9s
    so it's safe to do so.

    Personally, I am not going to spend many hours trying to decipher what all that code is trying to do (or is actually doing). And I'm not sure what the button click is supposed to invoke from out of that mess of code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    629
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Code:
    <input type = "button" value = "Click me to run a script" onclick = "myJavascriptFunction()">
    I think you're missing a semicolon ( at the end:

    Code:
    <input type = "button" value = "Click me to run a script" onclick = "myJavascriptFunction();">

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,159
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Quote Originally Posted by jalarie View Post
    Code:
    <input type = "button" value = "Click me to run a script" onclick = "myJavascriptFunction()">
    I think you're missing a semicolon ( at the end:

    Code:
    <input type = "button" value = "Click me to run a script" onclick = "myJavascriptFunction();">
    The semi-colon is optional and makes no difference here.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    To emphasize even more: The semi-colon is ALWAYS optional in JavaScript Jalarie: Are you relatively new to JavaScript? I see you have been here since 2002, but I'm guessing mostly in other languages?.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    629
    Thanks
    1
    Thanked 20 Times in 20 Posts
    [QUOTE=Old Pedant;1410950]The semi-colon is ALWAYS optional in JavaScript,/QUOTE]

    if I wish to run two separate functions from a single click, I could:
    Code:
    <a href="javascript:void(0);" onclick="function1();function2();">Click here</a>
    How would you code this without the semi-colon?

    Quote Originally Posted by Old Pedant View Post
    Jalarie: Are you relatively new to JavaScript? I see you have been here since 2002, but I'm guessing mostly in other languages?.
    Nope. JavaScript (I see that you spell it with the capital "S" in the middle just as I do.) has been one of my favorite languages for many years. I don't yet know it all and never expect to know all there is; that's why I participate in multiple forums. I like to learn.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,159
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    [QUOTE=jalarie;1411518]
    Quote Originally Posted by Old Pedant View Post
    The semi-colon is ALWAYS optional in JavaScript,/QUOTE]

    if I wish to run two separate functions from a single click, I could:
    Code:
    <a href="javascript:void(0);" onclick="function1();function2();">Click here</a>
    How would you code this without the semi-colon?



    Nope. JavaScript (I see that you spell it with the capital "S" in the middle just as I do.) has been one of my favorite languages for many years. I don't yet know it all and never expect to know all there is; that's why I participate in multiple forums. I like to learn.
    You should never use <a href="javascript:void(0);" If you don't want the <a> tag to go anywhere when JavaScript is disabled then use <button> instead and style it to look the way you want. <button> functions identically with <a> but without the href action.

    The semi-colon in your example is HTML markup, not JavaScript. In fact it still works with a comma!

    Code:
    <input type="button" value = "Click Me" onclick="one(), two(), three(), four()"/>
    
    <script type = "text/javascript">
    function one() {
    alert("One");
    }
    function two() {
    alert("Two");
    }
    function three() {
    alert("Three");
    }
    function four() {
    alert("Four");
    }
    
    </script>
    Last edited by Philip M; 09-05-2014 at 04:15 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    629
    Thanks
    1
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by Philip M View Post
    It still works with a comma!
    Ah! I just learned something! That's why I come here. Thank you.

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,159
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Quote Originally Posted by jalarie View Post
    Ah! I just learned something! That's why I come here. Thank you.
    Always nice to help someone learn something, but you have only thanked your helpers once in 12 years.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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