digic25
04-27-2006, 01:49 PM
This scripts runs at first but then it brings up an error message when I hit submit. Any help is appreciated.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>The Result of the course</title>
<script language="JavaScript">
function trim(s) {
while (s.charAt(0) == ' ')
s = s.substring(1);
while (s.charAt(s.length - 1)== ' ')
s = s.substring(0, s.length - 2);
return s;
}
function check(name)
{
var x = document.getElementById(ALastName);
var s = new String(x.value);
s = trim(s);
if(s == "")
{
alert("Please enter your " + LastName);
javascript:history.go(0);
}
var x = document.getElementById(AFirstNname);
var s = new String(x.value);
s = trim(s);
if(s == "")
{
alert("Please enter your " + FirstName);
javascript:history.go(0);
}
else
x.value = s;
}
</script>
</head>
<body>
<form action="http://matrix.csis.pace.edu/~badii/Exercise12.php" method="post">
<label for="lname">Last name: </label>
<input type="text" name="LastName" id="ALastName" size="20"><br><br>
<label for="fname">First name: </label>
<input type="text" name="FirstName" id="AFirstName" size="20"><br><br>
<input type="submit" name="submit" id="submit" value=" Submit "
onclick = "check('LastName'); check('FirstName')">
</form>
</body>
</html>
Thanks
Tom
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>The Result of the course</title>
<script language="JavaScript">
function trim(s) {
while (s.charAt(0) == ' ')
s = s.substring(1);
while (s.charAt(s.length - 1)== ' ')
s = s.substring(0, s.length - 2);
return s;
}
function check(name)
{
var x = document.getElementById(ALastName);
var s = new String(x.value);
s = trim(s);
if(s == "")
{
alert("Please enter your " + LastName);
javascript:history.go(0);
}
var x = document.getElementById(AFirstNname);
var s = new String(x.value);
s = trim(s);
if(s == "")
{
alert("Please enter your " + FirstName);
javascript:history.go(0);
}
else
x.value = s;
}
</script>
</head>
<body>
<form action="http://matrix.csis.pace.edu/~badii/Exercise12.php" method="post">
<label for="lname">Last name: </label>
<input type="text" name="LastName" id="ALastName" size="20"><br><br>
<label for="fname">First name: </label>
<input type="text" name="FirstName" id="AFirstName" size="20"><br><br>
<input type="submit" name="submit" id="submit" value=" Submit "
onclick = "check('LastName'); check('FirstName')">
</form>
</body>
</html>
Thanks
Tom