Page 1 of 1

need some new eyes.

Posted: Thu Oct 25, 2007 4:09 pm
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

Posted: Thu Oct 25, 2007 4:50 pm
by VladSun
You need semicolumn after each code line ... E.g.:

Code: Select all

var name1=prompt("Please enter name");

Posted: Thu Oct 25, 2007 5:35 pm
by Kieran Huggins
you need to run the function

Posted: Thu Oct 25, 2007 6:45 pm
by Gimpy
Why doesnt it goto msn after the alert box?

Posted: Thu Oct 25, 2007 6:58 pm
by VladSun
I would use:

Code: Select all

window.location.replace("http://msn.com")
instead

Posted: Thu Oct 25, 2007 7:01 pm
by feyd
I would use a server-side script instead.

Posted: Thu Oct 25, 2007 7:04 pm
by Gimpy
Thanks feyd and Vladsun and everyone else for their responses. You all have been tremendous help!

Posted: Fri Oct 26, 2007 10:56 am
by pickle
Sounds like a fun site to get into ;)

Posted: Sat Oct 27, 2007 3:07 pm
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.

Posted: Sat Oct 27, 2007 3:21 pm
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. ;)