Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question: how to debug JS

Status
Not open for further replies.

DotNetter

Programmer
May 19, 2005
194
US
I have the following code:
Code:
<html>
<head>

<title>Untitled</title>

<script>
function checkName(){
	//alert("Hi!")
	var UserName = document.myForm.UserName.value;
	if (UserName == "ME") {
		alert("Hello, YOU!!!");
	else
		alert("Hi, " + UserName + "!");
	}

	return (true);
}
//-->
</script>

</head>

<body>


<form name="myForm" onSubmit="return checkName()">

	<input type ="text" name="UserName">
	<input type ="submit" value="SUBMIT">
	<input type="reset">

</form>
</body>
</html>
I'm getting sytax errors on lines 11 and 25.

1) What's wrong with my syntax?
2) Are there any sites that let you plug in a script and they help you debug them?

Thanks!
Dot
 
Use FireFox - it has a built-in Javascript Console - which has more meaningful error messages.

[cheers]
Cheers!
Laura
 
You forget the braces fir the else statement.


<html>
<head>

<title>Untitled</title>

<script>
function checkName()
{
var UserName = document.myForm.UserName.value;
if (UserName == "ME")
{
alert("Hello, YOU!!!");
}
else
{
alert("Hi, " + UserName + "!");
}

return (true);
}
//-->
</script>

</head>

<body>


<form name="myForm" onSubmit="return checkName()">

<input type ="text" name="UserName">
<input type ="submit" value="SUBMIT">
<input type="reset">

</form>
</body>
</html>
 
What browser are you using.

I just run the sample above in IE,Firefox and Netscape and it work

 
I find that testing JS in older browsers is the easiest way to debug JS. I normally use NS 3.0, which I find is better than later NS. Unable to use FF, and IE sucks big time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top