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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 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; 09-11-2011 at 02:54 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,712
    Thanks
    25
    Thanked 660 Times in 659 Posts
    It's a matter of the quotes.
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function CaptainObvious(item)
    {
    	alert("Captain Obvious:You have clicked on a button that says "+ item);
    	alert("Just fulfilling my public duties.")
    }
    </script>
    </head>
    <body>
    <form>
    <input type="button" value="Apple" onclick="CaptainObvious('apple')" >
    </form>
    </body>
    </html>

  • #3
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote 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

  • #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Neeeevermind.
    Last edited by McTater; 09-12-2011 at 01:54 AM.


  •  

    Tags for this Thread

    Posting Permissions

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