codenewb
11-27-2012, 02:33 AM
Hi guys, I have been working on a form with validation script and I had it almost finished but when I went back to check and see if everything was still working I had broken everything else. My simple check for text and number code doesn't even work....would anybody be willing to look at it for me to see if they can figure out why it doesn't work....It's not a 100% done yet so i know some of the functions wont work yet...any help is appreciated.
Here goes nothing...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Cal U Course Registration Form</title>
<script type="text/javascript">
<!--
function checkForNumber(fieldValue) {
var numberCheck = isNaN(fieldValue);
if (numberCheck == true) {
window.alert("You must enter a numeric value!");
return false;
}
}
function checkForText(fieldValue) {
var numberCheck = isNaN(fieldValue);
if (numberCheck == false) {
window.alert("You cannot enter a numeric value!");
return false;
}
}
function checkForState() {
var StatesAbbreviations =
'AK,AL,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,'
+ 'MS,MT,NB,NC,ND,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY,';
if (StatesAbbreviations.indexOf(document.forms[0].state_registration.value + ',') == -1) {
alert("You did not enter a valid state code! Both letters must be capital!");
document.myForm.state_registration.focus();
return false;
}
return true;
}
function confirmPassword() {
if (document.forms[0].password_confirm.value != document.forms[0].password.value) {
window.alert("You did not enter the same password!");
}
document.forms[0].password.focus();
}
function sameAddressInfo() {
if (document.forms[0].elements[4].checked == true) {
document.forms[0].address_tempregistration.value = document.forms[0].address_registration.value;
document.forms[0].city_tempregistration.value = document.forms[0].city_registration.value;
document.forms[0].state_tempregistration.value = document.forms[0].state_registration.value;
document.forms[0].zip_tempregistration.value = document.forms[0].zip_registration.value;
}
else {
document.forms[0].address_registration.value = "";
document.forms[0].city_registration.value = "";
document.forms[0].state_registration.value = "";
document.forms[0].zip_registration.value = "";
}
}
function confirmSubmit() {
var submitForm = window.confirm("Are you sure you want to submit the form?");
if (submitForm == true)
return true;
return false;
}
function confirmResetform() {
var resetForm = window.confirm("Are you sure you want to reset the form?");
if (resetForm)
return true;
return false;
}
function nameCheck() {
if (document.forms[0].name_registration.value = "") {
document.forms[0].name_registration.value.focus();
window.alert("You have not entered your name!");
return false;
}
}
function cwidCheck() {
if (document.forms[0].cwid_registration.value = "") {
document.forms[0].cwid_registration.value.focus();
window.alert("You have not entered your CWID!");
return false;
}
}
function addressCheck() {
if (document.forms[0].address_registration.value = "") {
document.forms[0].address_registration.value.focus();
window.alert("You have not entered an adress!");
return false;
}
}
function cityCheck() {
if (document.forms[0].city_registration.value = "") {
document.forms[0].city_registration.value.focus();
window.alert("You have not entered a city!");
return false;
}
}
function stateCheck() {
if (document.forms[0].state_registration.value = "") {
document.forms[0].state_registration.value.focus();
window.alert("You have not entered a state!");
return false;
}
}
function zipCheck() {
if (document.forms[0].zip_registration.value = "") {
document.forms[0].zip_registration.value.focus();
window.alert("You have not entered a zip!");
return false;
}
}
function tempAddressCheck() {
if (document.forms[0].tempaddress_registration.value = "") {
document.forms[0].tempaddress_registration.value.focus();
window.alert("You have not entered an adress!");
return false;
}
}
function tempCityCheck() {
if (document.forms[0].tempcity_registration.value = "") {
document.forms[0].tempcity_registration.value.focus();
window.alert("You have not entered a city!");
return false;
}
}
function tempStateCheck() {
if (document.forms[0].tempstate_registration.value = "") {
document.forms[0].tempstate_registration.value.focus();
window.alert("You have not entered a state!");
return false;
}
}
function tempZipCheck() {
if (document.forms[0].tempzip_registration.value = "") {
document.forms[0].tempzip_registration.value.focus();
window.alert("You have not entered a zip!");
return false;
}
}
function areaCodeCheck() {
if (document.forms[0].area.value = "") {
document.forms[0].area.value.focus();
window.alert("You have not entered a area code!");
return false;
}
}
function exchangeCodeCheck() {
if (document.forms[0].exchange.value = "") {
document.forms[0].exchange.value.focus();
window.alert("You have not entered a exchange code!");
return false;
}
}
function phoneCodeCheck() {
if (document.forms[0].phone.value = "") {
document.forms[0].phone.value.focus();
window.alert("You have not entered a phone code!");
return false;
}
}
function passwordCheck() {
if (document.forms[0].password.value = "") {
document.forms[0].password.value.focus();
window.alert("You have not entered a password!");
return false;
}
}
function classRankCheck() {
var rankselect = false;
for (var i=0;i<document.forms[0].registrationrank.length;i++)
{
if(document.forms[0].registrationrank[i].checked)
rankselect=true;
}
if(!rankselect)
{
window.alert("Please select a class rank!");
return false;
}
}
function majorCheck() {
var majorsSelected = false;
for (var i=0; i<5; i++) {
if (document.forms[0].majors[i].checked == true) {
majorsSelected = true;
break;
}
}
if (majorsSelected == false) {
window.alert("You must select at least one major!");
return majorsSelected;
}
else
return majorsSelected;
}
function semesterCheck() {
if (document.forms[0].semester.value = "") {
window.alert("You have not selected a semester!");
return false;
}
}
function courseCheck() {
if (document.forms[0].multiple.selectedIndex == -1) {
window.alert("You must select at least one course!");
return false;
}
else
return true;
}
function submitFunctionCheck() {
if ( nameCheck == false ||
cwidCheck == false ||
addressCheck == false ||
cityCheck == false ||
stateCheck == false ||
zipCheck == false ||
tempAddressCheck == false ||
tempCityCheck == false ||
tempStateCheck == false ||
tempZipCheck == false ||
areaCodeCheck == false ||
exchangeCodeCheck == false ||
phoneCodeCheck == false ||
passwordCheck == false ||
classRankCheck == false ||
majorCheck == false ||
semesterCheck == false ||
courseCheck == false ||
//-->
</script>
</head>
<body>
<h1>Cal U Course Registration Form</h1>
<p>*Please note that all information is required on this form and all fields must include valid data*</p>
<p>*Name cannot include any numbers CWID must contain only numbers <br />
*Permanent and Temporary address must each be filled out or the Same address button must be selected<br />
*The State field must only contain two uppercase letters, Zip code must only contain 5 numbers<br />
*Telephone number must contain only numbers <br />
*You must choose at least one class rank, major, semester, and class <br />
*To select more than one course hold down the ctrl key and then click your selected classes.
</p>
<h2>Student Information</h2>
<form action="FormProcessor.html" method="get" enctype="application/x-www-form-urlencoded" onsubmit="return confirmSubmit();" onreset="return confirmResetform();" />
<p><strong>Name</strong><input type="text" name="name_registration" size="50" onchange="return checkForText(this.value);"/></p> <!--Displays the name text box//-->
<p><strong>CWID</strong><input type="text" name="cwid_registration" size="50" maxlength="8" onchange="return checkForNumber(this.value);"/></p> <!--Displays the CWID text box//-->
<table border="0">
<tr>
<td valign="top"><h3>Permanent Address</h3> <!--New table for permanent address//-->
<p>Address<br />
<input type="text" name="address_registration" size="50" /></p> <!--Displays the address text box//-->
<p>City, State, Zip<br />
<input type="text" name="city_registration" size="34" onchange="return checkForText(this.value);"/> <!--Displays the city text box//-->
<input type="text" name="state_registration" size="2" maxlength="2" onchange="return checkForState(this.value);"/> <!--Displays the state text box and limits the size to 2//-->
<input type="text" name="zip_registration" size="5" maxlength="5" onchange="return checkForNumber(this.value);" /></p> <!--Displays the zip text box and limits the size to 5//-->
<p><input type="checkbox" onclick="sameAddressInfo();" />Click here if your permanent address and temporary address are the same </p> <!--Displays the checkbox to select if both addresses are the same//-->
</td>
<td valign="top"><h3>Temporary Address</h3> <!--New table for temporary address//-->
<p>Address<br />
<input type="text" name="address_tempregistration" size="50" /></p> <!--Displays the temp address text box//-->
<p>City, State, Zip<br />
<input type="text" name="city_tempregistration" size="34" onchange="return checkForText(this.value);"/> <!--Displays the temp city text box//-->
<input type="text" name="state_tempregistration" size="2" maxlength="2" /> <!--Displays the temp state text box and limits the size to 2//-->
<input type="text" name="zip_tempregistration" size="5" maxlength="5" onchange="return checkForNumber(this.value);" /></p> <!--Displays the temp zip text box and limits the size to 5 and checks for a valid number//-->
</td>
</tr>
</table>
<p><strong>Telephone</strong> <!--Displays the name text box and creates 3 max lengths for each section of the phone #//-->
(<input type="text" name="area" size="3" maxlength="3" onchange="return checkForNumber(this.value);"/>)
<input type="text" name="exchange" size="3" maxlength="3" onchange="return checkForNumber(this.value);"/>
<input type="text" name="phone" size="4" maxlength="4" onchange="return checkForNumber(this.value);"/></p>
<p><strong>Enter a password you can use to manage your account online:</strong></p> <!--Displays the password text box//-->
<p><input type="password" name="password" size="30" /></p>
<p><strong>Type the password again to confirm it.</strong></p> <!--Displays the confirm password text box//-->
<p><input type="password" name="password_confirm" size="30" onblur="confirmPassword();" /></p>
<strong>Select your current class rank:</strong><br /> <!--Displays the class rank radio buttons//-->
<input type="radio" name="registrationrank" value="1" />Freshman
<input type="radio" name="registrationrank" value="2" />Sophomore
<input type="radio" name="registrationrank" value="3" />Junior
<input type="radio" name="registrationrank" value="4" />Senior
<p>Select your major(s).</p> <!--Displays the major check boxes//-->
<p>
<input type="checkbox" name="majors" value="1" />Business<br />
<input type="checkbox" name="majors" value="2" />Computer Engineering Technology<br />
<input type="checkbox" name="majors" value="3" />Computer Information Systems<br />
<input type="checkbox" name="majors" value="4" />Computer Science<br />
<input type="checkbox" name="majors" value="5" />Other<br />
</p>
<h3>Select the semester for which you are registering.</h3> <!--Displays the drop down list for semesters and limits the choice to 1//-->
<p><select name="semester">
<option value="">Choose One:</option>
<option value="1">Fall</option>
<option value="2">Spring</option>
<option value="3">Summer</option>
<option value="4">Special Session</option>
</select></p>
<h3>Select the courses for which you are registering.</h3> <!--Displays the courses drop down list and all can be selected//-->
<p><select multiple="multiple">
<option value="cis110">CIS 110 Intro to Information Systems</option>
<option value="cis120">CIS 120 Application Programming I</option>
<option value="cis220">CIS 220 Application Programming II</option>
<option value="cis299">CIS 299 Systems Analysis I</option>
<option value="cis322">CIS 322 Database Application Development</option>
<option value="cis332">CIS 332 Web Programming II</option>
<option value="cis341">CIS 341 CISCO CCNA 1</option>
<option value="cis343">CIS 343 CISCO CCNA 3</option>
<option value="cis352">CIS 352 Global, Economic and Social Ethical Issues in Computing</option>
<option value="cis492">CIS 492 Senior Project II</option>
</select></p>
<input type="submit" value="Submit" />
<input type="reset" value="Clear" />
</form>
</body>
</html>
The submit function check isn't done yet but everything should be...
Here goes nothing...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Cal U Course Registration Form</title>
<script type="text/javascript">
<!--
function checkForNumber(fieldValue) {
var numberCheck = isNaN(fieldValue);
if (numberCheck == true) {
window.alert("You must enter a numeric value!");
return false;
}
}
function checkForText(fieldValue) {
var numberCheck = isNaN(fieldValue);
if (numberCheck == false) {
window.alert("You cannot enter a numeric value!");
return false;
}
}
function checkForState() {
var StatesAbbreviations =
'AK,AL,AR,AZ,CA,CO,CT,DC,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,'
+ 'MS,MT,NB,NC,ND,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY,';
if (StatesAbbreviations.indexOf(document.forms[0].state_registration.value + ',') == -1) {
alert("You did not enter a valid state code! Both letters must be capital!");
document.myForm.state_registration.focus();
return false;
}
return true;
}
function confirmPassword() {
if (document.forms[0].password_confirm.value != document.forms[0].password.value) {
window.alert("You did not enter the same password!");
}
document.forms[0].password.focus();
}
function sameAddressInfo() {
if (document.forms[0].elements[4].checked == true) {
document.forms[0].address_tempregistration.value = document.forms[0].address_registration.value;
document.forms[0].city_tempregistration.value = document.forms[0].city_registration.value;
document.forms[0].state_tempregistration.value = document.forms[0].state_registration.value;
document.forms[0].zip_tempregistration.value = document.forms[0].zip_registration.value;
}
else {
document.forms[0].address_registration.value = "";
document.forms[0].city_registration.value = "";
document.forms[0].state_registration.value = "";
document.forms[0].zip_registration.value = "";
}
}
function confirmSubmit() {
var submitForm = window.confirm("Are you sure you want to submit the form?");
if (submitForm == true)
return true;
return false;
}
function confirmResetform() {
var resetForm = window.confirm("Are you sure you want to reset the form?");
if (resetForm)
return true;
return false;
}
function nameCheck() {
if (document.forms[0].name_registration.value = "") {
document.forms[0].name_registration.value.focus();
window.alert("You have not entered your name!");
return false;
}
}
function cwidCheck() {
if (document.forms[0].cwid_registration.value = "") {
document.forms[0].cwid_registration.value.focus();
window.alert("You have not entered your CWID!");
return false;
}
}
function addressCheck() {
if (document.forms[0].address_registration.value = "") {
document.forms[0].address_registration.value.focus();
window.alert("You have not entered an adress!");
return false;
}
}
function cityCheck() {
if (document.forms[0].city_registration.value = "") {
document.forms[0].city_registration.value.focus();
window.alert("You have not entered a city!");
return false;
}
}
function stateCheck() {
if (document.forms[0].state_registration.value = "") {
document.forms[0].state_registration.value.focus();
window.alert("You have not entered a state!");
return false;
}
}
function zipCheck() {
if (document.forms[0].zip_registration.value = "") {
document.forms[0].zip_registration.value.focus();
window.alert("You have not entered a zip!");
return false;
}
}
function tempAddressCheck() {
if (document.forms[0].tempaddress_registration.value = "") {
document.forms[0].tempaddress_registration.value.focus();
window.alert("You have not entered an adress!");
return false;
}
}
function tempCityCheck() {
if (document.forms[0].tempcity_registration.value = "") {
document.forms[0].tempcity_registration.value.focus();
window.alert("You have not entered a city!");
return false;
}
}
function tempStateCheck() {
if (document.forms[0].tempstate_registration.value = "") {
document.forms[0].tempstate_registration.value.focus();
window.alert("You have not entered a state!");
return false;
}
}
function tempZipCheck() {
if (document.forms[0].tempzip_registration.value = "") {
document.forms[0].tempzip_registration.value.focus();
window.alert("You have not entered a zip!");
return false;
}
}
function areaCodeCheck() {
if (document.forms[0].area.value = "") {
document.forms[0].area.value.focus();
window.alert("You have not entered a area code!");
return false;
}
}
function exchangeCodeCheck() {
if (document.forms[0].exchange.value = "") {
document.forms[0].exchange.value.focus();
window.alert("You have not entered a exchange code!");
return false;
}
}
function phoneCodeCheck() {
if (document.forms[0].phone.value = "") {
document.forms[0].phone.value.focus();
window.alert("You have not entered a phone code!");
return false;
}
}
function passwordCheck() {
if (document.forms[0].password.value = "") {
document.forms[0].password.value.focus();
window.alert("You have not entered a password!");
return false;
}
}
function classRankCheck() {
var rankselect = false;
for (var i=0;i<document.forms[0].registrationrank.length;i++)
{
if(document.forms[0].registrationrank[i].checked)
rankselect=true;
}
if(!rankselect)
{
window.alert("Please select a class rank!");
return false;
}
}
function majorCheck() {
var majorsSelected = false;
for (var i=0; i<5; i++) {
if (document.forms[0].majors[i].checked == true) {
majorsSelected = true;
break;
}
}
if (majorsSelected == false) {
window.alert("You must select at least one major!");
return majorsSelected;
}
else
return majorsSelected;
}
function semesterCheck() {
if (document.forms[0].semester.value = "") {
window.alert("You have not selected a semester!");
return false;
}
}
function courseCheck() {
if (document.forms[0].multiple.selectedIndex == -1) {
window.alert("You must select at least one course!");
return false;
}
else
return true;
}
function submitFunctionCheck() {
if ( nameCheck == false ||
cwidCheck == false ||
addressCheck == false ||
cityCheck == false ||
stateCheck == false ||
zipCheck == false ||
tempAddressCheck == false ||
tempCityCheck == false ||
tempStateCheck == false ||
tempZipCheck == false ||
areaCodeCheck == false ||
exchangeCodeCheck == false ||
phoneCodeCheck == false ||
passwordCheck == false ||
classRankCheck == false ||
majorCheck == false ||
semesterCheck == false ||
courseCheck == false ||
//-->
</script>
</head>
<body>
<h1>Cal U Course Registration Form</h1>
<p>*Please note that all information is required on this form and all fields must include valid data*</p>
<p>*Name cannot include any numbers CWID must contain only numbers <br />
*Permanent and Temporary address must each be filled out or the Same address button must be selected<br />
*The State field must only contain two uppercase letters, Zip code must only contain 5 numbers<br />
*Telephone number must contain only numbers <br />
*You must choose at least one class rank, major, semester, and class <br />
*To select more than one course hold down the ctrl key and then click your selected classes.
</p>
<h2>Student Information</h2>
<form action="FormProcessor.html" method="get" enctype="application/x-www-form-urlencoded" onsubmit="return confirmSubmit();" onreset="return confirmResetform();" />
<p><strong>Name</strong><input type="text" name="name_registration" size="50" onchange="return checkForText(this.value);"/></p> <!--Displays the name text box//-->
<p><strong>CWID</strong><input type="text" name="cwid_registration" size="50" maxlength="8" onchange="return checkForNumber(this.value);"/></p> <!--Displays the CWID text box//-->
<table border="0">
<tr>
<td valign="top"><h3>Permanent Address</h3> <!--New table for permanent address//-->
<p>Address<br />
<input type="text" name="address_registration" size="50" /></p> <!--Displays the address text box//-->
<p>City, State, Zip<br />
<input type="text" name="city_registration" size="34" onchange="return checkForText(this.value);"/> <!--Displays the city text box//-->
<input type="text" name="state_registration" size="2" maxlength="2" onchange="return checkForState(this.value);"/> <!--Displays the state text box and limits the size to 2//-->
<input type="text" name="zip_registration" size="5" maxlength="5" onchange="return checkForNumber(this.value);" /></p> <!--Displays the zip text box and limits the size to 5//-->
<p><input type="checkbox" onclick="sameAddressInfo();" />Click here if your permanent address and temporary address are the same </p> <!--Displays the checkbox to select if both addresses are the same//-->
</td>
<td valign="top"><h3>Temporary Address</h3> <!--New table for temporary address//-->
<p>Address<br />
<input type="text" name="address_tempregistration" size="50" /></p> <!--Displays the temp address text box//-->
<p>City, State, Zip<br />
<input type="text" name="city_tempregistration" size="34" onchange="return checkForText(this.value);"/> <!--Displays the temp city text box//-->
<input type="text" name="state_tempregistration" size="2" maxlength="2" /> <!--Displays the temp state text box and limits the size to 2//-->
<input type="text" name="zip_tempregistration" size="5" maxlength="5" onchange="return checkForNumber(this.value);" /></p> <!--Displays the temp zip text box and limits the size to 5 and checks for a valid number//-->
</td>
</tr>
</table>
<p><strong>Telephone</strong> <!--Displays the name text box and creates 3 max lengths for each section of the phone #//-->
(<input type="text" name="area" size="3" maxlength="3" onchange="return checkForNumber(this.value);"/>)
<input type="text" name="exchange" size="3" maxlength="3" onchange="return checkForNumber(this.value);"/>
<input type="text" name="phone" size="4" maxlength="4" onchange="return checkForNumber(this.value);"/></p>
<p><strong>Enter a password you can use to manage your account online:</strong></p> <!--Displays the password text box//-->
<p><input type="password" name="password" size="30" /></p>
<p><strong>Type the password again to confirm it.</strong></p> <!--Displays the confirm password text box//-->
<p><input type="password" name="password_confirm" size="30" onblur="confirmPassword();" /></p>
<strong>Select your current class rank:</strong><br /> <!--Displays the class rank radio buttons//-->
<input type="radio" name="registrationrank" value="1" />Freshman
<input type="radio" name="registrationrank" value="2" />Sophomore
<input type="radio" name="registrationrank" value="3" />Junior
<input type="radio" name="registrationrank" value="4" />Senior
<p>Select your major(s).</p> <!--Displays the major check boxes//-->
<p>
<input type="checkbox" name="majors" value="1" />Business<br />
<input type="checkbox" name="majors" value="2" />Computer Engineering Technology<br />
<input type="checkbox" name="majors" value="3" />Computer Information Systems<br />
<input type="checkbox" name="majors" value="4" />Computer Science<br />
<input type="checkbox" name="majors" value="5" />Other<br />
</p>
<h3>Select the semester for which you are registering.</h3> <!--Displays the drop down list for semesters and limits the choice to 1//-->
<p><select name="semester">
<option value="">Choose One:</option>
<option value="1">Fall</option>
<option value="2">Spring</option>
<option value="3">Summer</option>
<option value="4">Special Session</option>
</select></p>
<h3>Select the courses for which you are registering.</h3> <!--Displays the courses drop down list and all can be selected//-->
<p><select multiple="multiple">
<option value="cis110">CIS 110 Intro to Information Systems</option>
<option value="cis120">CIS 120 Application Programming I</option>
<option value="cis220">CIS 220 Application Programming II</option>
<option value="cis299">CIS 299 Systems Analysis I</option>
<option value="cis322">CIS 322 Database Application Development</option>
<option value="cis332">CIS 332 Web Programming II</option>
<option value="cis341">CIS 341 CISCO CCNA 1</option>
<option value="cis343">CIS 343 CISCO CCNA 3</option>
<option value="cis352">CIS 352 Global, Economic and Social Ethical Issues in Computing</option>
<option value="cis492">CIS 492 Senior Project II</option>
</select></p>
<input type="submit" value="Submit" />
<input type="reset" value="Clear" />
</form>
</body>
</html>
The submit function check isn't done yet but everything should be...