ok … what’s wrong with this code. I’m getting the form, but I can’t get the friggin’ thing to verify the data entered for me Any help would be appreciated.
<html>
<head>
<title> Function - Passing Parameters & Returning Values</title>
<form name="form1" method="post" action="[email protected]">
<h2><center>Computer Order Form</h2>
<h3>You have to be 18 or over to order </center></h3>
<h4>Please enter your name and age below: </h4>
Name:
<input type="text" name="custName" value="" >
Age:
<input type="text" name="custAge" value="" size="2" >
<h4>Select your CPU speed: </h4>
<input type="radio" name="cpuSpeed" value="800 MHz">800 MHz
<input type="radio" name="cpuSpeed" value="1.2 GHz">1.2 GHz
<input type="radio" name="cpuSpeed" value="1.8 GHz">1.8 GHz
<input type="radio" name="cpuSpeed" value="2.2 GHz" checked="checked"> 2.2 GHz
<h4>Select the accessories you want: </h4>
<input type="checkbox" name="dvd rom" value="DVD ROM">DVD ROM
<input type="checkbox" name="cd rw" value="CD R/W">CD R/W
<input type="checkbox" name="dvd rw" value="DVD R/W">DVD R/W
<input type="checkbox" name="DigiCam" value="DigiCam">DigiCam
<input type="submit" value="Submit" />
</form>
<script language="JavaScript">
function age_onblur() {
var customerAge = document.form1.custAge;
if (isNaN(customerAge.value) == true)
{ window.alert("Please enter a number for age");
customerAge.focus() ; //focus on field
customerAge.select() ; //select current entry for replacement
}
else
{ if(customerAge.value < 18)
{ window.alert("To order, you must be 18 or older.
If entered wrong, please enter correct age.");
customerAge.focus();
customerAge.select(); }
} }
function checkForm() {
if (document.form1.custName.value == ""|| document.form1.custAge.value == "")
{ window.alert("Please enter both Name and Age");
if (document.form1.custName.value == "")
{document.form1.custName.focus() ; }
else
{document.form1.custAge.focus() ; }
} }
</script>
</head>
</html>
ok i have looked at the code ... !
2 major problems .... several small ones ...
first major problem: ur code does not have a
tag. The form must go in the body ... !!! not in the head ... only the javascript function go in the head..
second major problem is that the form action should lead to a javascript function (as sadzz pointed out).. onClink = someValidation() or client side and action = someValidation.(jsp or asp or php) (for server side)...
Thanks man … fixed both of these problems. U guys are some real good debuggers. :k:
and BTW … I do my assignments myself, but the prof for this course is a REAL @$$hole. so I never go to class. You should listen to his hard Indian accent