JavaScript and client side scripting.
Moderator: General Moderators
Gimpy
Forum Commoner
Posts: 42 Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:
Post
by Gimpy » Thu Oct 25, 2007 4:09 pm
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.
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
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Thu Oct 25, 2007 4:50 pm
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
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Thu Oct 25, 2007 5:35 pm
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 » Thu Oct 25, 2007 6:45 pm
Why doesnt it goto msn after the alert box?
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Thu Oct 25, 2007 6:58 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Oct 25, 2007 7:01 pm
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 » Thu Oct 25, 2007 7:04 pm
Thanks feyd and Vladsun and everyone else for their responses. You all have been tremendous help!
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Fri Oct 26, 2007 10:56 am
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.
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Sat Oct 27, 2007 3:07 pm
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Oct 27, 2007 3:21 pm
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.