Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-11-2011, 01:11 PM   PM User | #1
McTater
New to the CF scene

 
Join Date: Sep 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
McTater is an unknown quantity at this point
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 01:54 PM..
McTater is offline   Reply With Quote
Old 09-11-2011, 02:28 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,383
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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>
sunfighter is offline   Reply With Quote
Old 09-11-2011, 07:40 PM   PM User | #3
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
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
Logic Ali is offline   Reply With Quote
Old 09-12-2011, 12:29 AM   PM User | #4
McTater
New to the CF scene

 
Join Date: Sep 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
McTater is an unknown quantity at this point
Neeeevermind.

Last edited by McTater; 09-12-2011 at 12:54 AM..
McTater is offline   Reply With Quote
Reply

Bookmarks

Tags
argument, javascript, newbie, passing, problem

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:50 AM.


Advertisement
Log in to turn off these ads.