...

View Full Version : Problem passing an argument...



McTater
09-11-2011, 01:11 PM
I started Javascript yesterday. :confused:
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


<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?

sunfighter
09-11-2011, 02:28 PM
It's a matter of the quotes.

<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>

Logic Ali
09-11-2011, 07:40 PM
I started Javascript yesterday. :confused:
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

McTater
09-12-2011, 12:29 AM
Neeeevermind.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum