need some new eyes.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

need some new eyes.

Post by Gimpy »

Ok, I'm trying to learn some Javascript and im messing with this and I can figure it, anybody care to help? it just displays a blank page with nothing. :? :? :? :cry: :cry: :cry:

Code: Select all

function get_name()
{
		var name1=prompt("Please enter name")
		var age=prompt("Please enter your age")
               
		if(age <21)
				{
				alert("sorry "+name1+", you're only "+age+", Here's a site just for you.")
				window.location("http://www.msn.com")
				}
		else{
			alert("Hello "+name1+", Since you're "+age+", you may view this site.")
		      }
            }

Thanks in advance,
bryan
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

You need semicolumn after each code line ... E.g.:

Code: Select all

var name1=prompt("Please enter name");
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you need to run the function
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

Post by Gimpy »

Why doesnt it goto msn after the alert box?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

I would use:

Code: Select all

window.location.replace("http://msn.com")
instead
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I would use a server-side script instead.
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

Post by Gimpy »

Thanks feyd and Vladsun and everyone else for their responses. You all have been tremendous help!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Sounds like a fun site to get into ;)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

VladSun wrote:You need semicolumn after each code line ... E.g.:

Code: Select all

var name1=prompt("Please enter name");
Not so. Semicolons are optional in Javascript.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

califdon wrote:
VladSun wrote:You need semicolumn after each code line ... E.g.:

Code: Select all

var name1=prompt("Please enter name");
Not so. Semicolons are optional in Javascript.
They're only partially optional, actually. Try passing a file that doesn't have semicolons for each statement into a typical javascript compressing script. Your browser will explode with errors. ;)
Post Reply