I was given this assignment:
Create an html form. Include at least two text boxes, at least one of which must be numeric, a set of at least three radio buttons, a submit button and a reset button. Upload to your account. Make sure the permissions are correct. Name it hw1.html. Create a php script called hw1.php using an ASCII text editor that takes the data and creates a simple response html page verifying the data entered. For full credit, an if statement using the value of the numeric field must be included to give different output (such as messages, colors, etc.) and error checking must be included. Submit the entire url in the dropbox.
I didn't know how to go about the "numeric only" thing so I decided I would use javascript to check the value before submittal. Unfortunately, it doesn't run at all and the form gets submitted regardless. Since its past due I feel comfortable asking for help. I want to know how I could have done this better and how I could've done it in javascript.
h1.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml$
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--
http://javascript.about.com/library/blva…
-->
<title>Homework 1</title>
<script type="text/javascript">
<!--
function onlyNumbers()
{
var b = document.getElementById('id').value;
if(isNaN(b))
{
alert("Numeric value for student id needed");
window.location.href="h1.html";
}
}
function checkForm()
{
var b = document.getElementById('id').value;
var d = b * 2;
if(d == b)
{
alert("Numeric value for student id needed");
document.forms['form'].submitit.disabled…
if(navigator.appName == "Microsoft Internet Explorer")
{
window.document.execCommand('Stop');
}
else
{
window.stop();
}
window.navigate("cs4.sunyocc.edu/~j.d.da…
}
else
{
document.forms['form'].submitit.disabled…
document.forms['form'].submit();
}
}
//-->
</script>
</head>
<body>
<form id="form" name="form" method="post" action="h1.php" onsubmit="checkform();">
<p>Name:<input type="text" name="name" id="name" /></p>
<p>Enter ID:<input type="text" name="id" id="id" /></p>
<p>You Are:
full time: <input type="radio" name="student" id="student" value="full" />
part time: <input type="radio" name="student" id="student" value="part" />
</p>
<p>Financial aid?<input type="checkbox" name="aid" value="yes" id="aid" /></p>
<input type="submit" name="submit" value="submit" />
<input type="button" name="reset" value="reset" onClick="window.navigate("cs4.sunyocc.ed…
</form>
</body>
</html>