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 12-06-2009, 03:09 PM   PM User | #1
sjjs1985
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
sjjs1985 is an unknown quantity at this point
help with basic javascript for uni assignement please! :-)

hi all, just got to make a basic form for my assignemment but i cant seem to get it to work. please could somebody point me in the right direction? thank you

Code:
<head>

<script type="text/javascript">

function make(myform)
{
var name = form.nameinput.value ;
var age = form.ageinput.value ;
var location = form.locationinput.value ;
var z = form.team.selectedIndex ;
var team = form.team.options[z].value;
alert("Thank you " + name + ".Good luck supporting " + team + );
}
</script>

</head>

<body>

<form method="get" action="" name="myform">
<h2>Order form</h2>
<fieldset>
<p>Please enter your details</p>
Name: <input type="text" value="" name="nameinput"/><br/>
Age: <input type="text" value="" size="2" name="ageinput"/><br/>
Location: <input type="text" value="" name="locationinput"/>

<p>Choose your favourite football team</p>
<select name="team">
<option value="arsenal">Arsenal</option>
<option value="aston_villa">Aston Villa</option>
<option value="birmingham_city">Birmingham City</option>
<option value="blackburn_rovers">Blackburn Rovers</option>
<option value="bolton_wanderers">Bolton Wanderers</option>
<option value="burnley">Burnley</option>
<option value="chelsea">Chelsea</option>
<option value="everton">Everton</option>
<option value="fulham">Fulham</option>
<option value="hull">Hull</option>
<option value="liverpool">Liverpool</option>
<option value="manchester_city">Manchester City</option>
<option value="manchester_united">Manchester United</option>
<option value="portsmouth">Portsmouth</option>
<option value="stoke_city">Stoke City</option>
<option value="sunderland">Sunderland</option>
<option value="tottenham_hotspur">Tottenham Hotspur</option>
<option value="west_ham">West Ham</option>
<option value="wigan_athletic">Wigan Athletic</option>
<option value="wolverhampton_wanderers">Wolverhampton Wanderers
</option>
</select>
</fieldset>
<input type="button" onclick="make(this.form)" value="Submit Details" name="button"/>
</form>

Last edited by sjjs1985; 12-06-2009 at 04:58 PM..
sjjs1985 is offline   Reply With Quote
Old 12-06-2009, 04:02 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Check this out:-

Code:
<script type="text/javascript">

function make(form) {
var name = form.nameinput.value ;
var age = form.ageinput.value ;
var location = form.locationinput.value ;
var z = form.team.selectedIndex ;
var team = form.team.options[z].value;
alert("Thank you " + name + ". Good luck supporting " + team + );
}
</script>
Bookshop Assistant: "This book about Javascript will save you half your work".
Lazy Student: "Oh good! I'll take two!"
Philip M is offline   Reply With Quote
Old 12-06-2009, 04:24 PM   PM User | #3
sjjs1985
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
sjjs1985 is an unknown quantity at this point
thanks for the reply but still no luck
sjjs1985 is offline   Reply With Quote
Old 12-06-2009, 04:47 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Well, it works fine for me. Check your error console. Did you correct the alert syntax?

BTW, you would do better to change
var team = form.team.options[z].value;
to
var team = form.team.options[z].text;

so that they are thanked for supporting
Blackburn Rovers
rather than
blackburn_rovers

or make the option values the same as the text.

Note that
function make(form) { //opening brace on same line
is to be preferred to
function make(form)
{
to avoid the risk of a fatal error of putting a semi-colon after function make(form)


BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in [code] tags. This means use the octothorpe or # button on the toolbar which will insert opening [ code ] and closing [ /code ] tags - omit the spaces. You can (and should) edit your previous post.

Last edited by Philip M; 12-06-2009 at 04:52 PM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
sjjs1985 (12-06-2009)
Old 12-06-2009, 04:53 PM   PM User | #5
randomuser773
Banned

 
Join Date: Nov 2008
Location: not found
Posts: 284
Thanks: 0
Thanked 53 Times in 51 Posts
randomuser773 can only hope to improve
Quote:
Originally Posted by sjjs1985 View Post
hi all, just got to make a basic form for my assignemment but i cant seem to get it to work. please could somebody point me in the right direction?
FireFox -> Tools / Error Console
randomuser773 is offline   Reply With Quote
Users who have thanked randomuser773 for this post:
sjjs1985 (12-06-2009)
Old 12-06-2009, 05:00 PM   PM User | #6
sjjs1985
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
sjjs1985 is an unknown quantity at this point
my error console says:

Error: syntax error
Source code:
alert("Thank you " + name + ". Good luck supporting " + team + );


and an arrow points to the last bracket.

all help greatly appreciated. thanking you for your time. sam
sjjs1985 is offline   Reply With Quote
Old 12-06-2009, 05:13 PM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
I have already pointed out to you the error:-

alert("Thank you " + name + ". Good luck supporting " + team + );
Philip M is offline   Reply With Quote
Old 12-06-2009, 05:22 PM   PM User | #8
sjjs1985
New to the CF scene

 
Join Date: Dec 2009
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
sjjs1985 is an unknown quantity at this point
ah stupid me. i didnt realise your red font meant it shouldnt be there! thanks all for the help!!
sjjs1985 is offline   Reply With Quote
Reply

Bookmarks

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 08:05 AM.


Advertisement
Log in to turn off these ads.