Web Analytics Made Easy -
StatCounter Problem passing an argument... - CodingForum

Announcement

Collapse
No announcement yet.

Problem passing an argument...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem passing an argument...

    I started Javascript yesterday.
    I am trying to make the function Captain Obvious simply say what button you are pressing in an alert box, but after I click the button, nothing happens at all, no error message or anything. I have tried it with no argument inside the script call, and then it sort-of works. The alert box comes up saying: "You have clicked on a button that says "undefined"." I am pretty sure that means that I am having a problem passing the argument when I call it, but to be honest I have no clue lol
    Code:
    <head>
    <script type="text/javascript">
    function CaptainObvious('choice')
    {
    	alert("Captain Obvious:You have clicked on a button that says ''"+choice+"''.");
    	alert("Just fulfilling my public duties.")
    }
    </script>
    </head>
    <body>
    <form>
    <input type="button" value="Apple" onclick=CaptainObvious("apple")>
    </form>
    Any ideas?
    Last edited by McTater; Sep 11, 2011, 08:54 AM.

  • #2
    It's a matter of the quotes.
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function CaptainObvious[COLOR="Red"](item)[/COLOR]
    {
    	alert("Captain Obvious:You have clicked on a button that says[COLOR="Red"] "+ item);[/COLOR]
    	alert("Just fulfilling my public duties.")
    }
    </script>
    </head>
    <body>
    <form>
    <input type="button" value="Apple"[COLOR="Red"] onclick="CaptainObvious('apple')" [/COLOR]>
    </form>
    </body>
    </html>
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

    Comment


    • #3
      Originally posted by McTater View Post
      I started Javascript yesterday.
      I am trying to make the function Captain Obvious simply say what button you are pressing in an alert box, but after I click the button, nothing happens at all, no error message or anything.
      You are getting an error message, just check the error console. GIYF

      Comment


      • #4
        Neeeevermind.
        Last edited by McTater; Sep 11, 2011, 07:54 PM.

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎