Data Validation

Data Validation

Page 1 of 1

1 Replies - 659 Views - Last Post: 03 March 2009 - 06:18 AM

#1 gwhit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-March 09

Data Validation

Posted 02 March 2009 - 04:58 PM

Why won't the phone part validate????
<style type="text/css">
body {background-color: lightblue}<!--Tells what color to make the background of webpage-->
h1 {background-color: transparent; text-align: center}<!-- First hypertext link in web page.-->
h2 {background-color: transparent; text-align: center}<!-- First hypertext link in web page.-->
<title>Survery</title><!--This is what appears at top of page in address bar-->
</style><!--Closes style.-->
<script>
var frm=document.getElementEyId('myform');
function validateForm() {
if(document.getElementById('fname').value=="" ) {
alert("Please enter a First Name!");
return false;
}
else if(document.getElementById('lname').value=="" ) {
alert("Please enter a Last Name!");
return false;
}
else {return true; }
}
else if(document.getElementById('phone').value=="" ) {
alert("Please enter a Phone Number!");
return false;
}
else {return true; }
}
</script>
</head><!--Closes the head.-->
<body>
<FORM ID="myform"><!--Opens the buttons for the submit and refresh.-->

<center>
<h1>Customer Information</h1>
<h2>Survey</h2>
</center>
<br>
<br>
<TABLE BORDER="6" cellpadding="10" cellspacing="0" width="100%"><!--Start of the table, outline setup.-->
<tr> <TD width=450>
<B> First Name</B><BR> <!--The five lines below are information in the table.-->
<INPUT ID="fname" NAME="first name" SIZE="30" CLASS="shadeform"><br>
<B>Last Name</B><BR>
<INPUT ID="lname" NAME="last name" SIZE="30" CLASS="shadeform"><br>
<B> Street Address</B><BR>
<INPUT NAME="street address" SIZE="30" CLASS="shadeform">

<br><B>State</B><!--This is where the information for the drop down starts.-->
<BR>
<select>
<option value=""></option>
<optgroup label="United States">
<option id="USA-AL" value="AL">Alabama (AL)</option>
<option id="USA-AK" value="AK">Alaska (AK)</option>
<option id="USA-AZ" value="AZ">Arizona (AZ)</option>
<option id="USA-AR" value="AR">Arkansas (AR)</option>
<option id="USA-CA" value="CA">California (CA)</option>
<option id="USA-CO" value="CO">Colorado (CO)</option>
<option id="USA-CT" value="CT">Connecticut (CT)</option>
<option id="USA-DE" value="DE">Delaware (DE)</option>
<option id="USA-FL" value="FL">Florida (FL)</option>
<option id="USA-GA" value="GA">Georgia (GA)</option>
<option id="USA-HI" value="HI">Hawaii (HI)</option>
<option id="USA-ID" value="ID">Idaho (ID)</option>
<option id="USA-IL" value="IL">Illinois (IL)</option>
<option id="USA-IN" value="IN">Indiana (IN)</option>
<option id="USA-IA" value="IA">Iowa (IA)</option>
<option id="USA-KS" value="KS">Kansas (KS)</option>
<option id="USA-KY" value="KY">Kentucky (KY)</option>
<option id="USA-LA" value="LA">Louisiana (LA)</option>
<option id="USA-ME" value="ME">Maine (ME)</option>
<option id="USA-MD" value="MD">Maryland (MD)</option>
<option id="USA-MA" value="MA">Massachusetts (MA)</option>
<option id="USA-MI" value="MI">Michigan (MI)</option>
<option id="USA-MN" value="MN">Minnesota (MN)</option>
<option id="USA-MS" value="MS">Mississippi (MS)</option>
<option id="USA-MO" value="MO">Missouri (MO)</option>
<option id="USA-MT" value="MT">Montana (MT)</option>
<option id="USA-NE" value="NE">Nebraska (NE)</option>
<option id="USA-NV" value="NV">Nevada (NV)</option>
<option id="USA-NH" value="NH">New Hampshire (NH)</option>
<option id="USA-NJ" value="NJ">New Jersey (NJ)</option>
<option id="USA-NM" value="NM">New Mexico (NM)</option>
<option id="USA-NY" value="NY">New York (NY)</option>
<option id="USA-NC" value="NC">North Carolina (NC)</option>
<option id="USA-ND" value="ND">North Dakota (ND)</option>
<option id="USA-OH" value="OH">Ohio (OH)</option>
<option id="USA-OK" value="OK">Oklahoma (OK)</option>
<option id="USA-OR" value="OR">Oregon (OR)</option>
<option id="USA-PA" value="PA">Pennyslvania (PA)</option>
<option id="USA-RI" value="RI">Rhode Island (RI)</option>
<option id="USA-SC" value="SC">South Carolina (SC)</option>
<option id="USA-SD" value="SD">South Dakota (SD)</option>
<option id="USA-TN" value="TN">Tennessee (TN)</option>
<option id="USA-TX" value="TX">Texas (TX)</option>
<option id="USA-UT" value="UT">Utah (UT)</option>
<option id="USA-VT" value="VT">Vermont (VT)</option>
<option id="USA-VA" value="VA">Virginia (VA)</option>
<option id="USA-WA" value="WA">Washington (WA)</option>
<option id="USA-WV" value="WV">West Virginia (WV)</option>
<option id="USA-WI" value="WI">Wisconsin (WI)</option>
<option id="USA-WY" value="WY">Wyoming (WY)</option>
<td><!--Provides another break in the table.-->
<br><!--The following eight lines are the left side of the table.-->
<B>City</B><BR>
<INPUT NAME="city" SIZE="30" CLASS="shadeform"><br>
<B>Zip Code</B><br>
<INPUT NAME="zipcode" SIZE="30" CLASS="shadeform"><br>
<B>Phone Number</B><BR>
<INPUT ID="phone" Name="phone" SIZE="30" CLASS="shadeform"><br>
<B>E-Mail</B><BR>
<INPUT Name="email" SIZE="30" CLASS="shadeform">
<br><br><!--Puts spaces in the program-->
</Table><br><!--Closes the table.-->
<center><!--Centers the buttons below.-->
<INPUT NAME="Submit Info" TYPE=Button VALUE="Submit Info" onclick="java script:validateForm()">
<INPUT type=button value="Refresh" onclick="window.location.reload()">[code]

Is This A Good Question/Topic? 0
  • +

Replies To: Data Validation

#2 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Data Validation

Posted 03 March 2009 - 06:18 AM

Your title element is inside your style tag. Also, you have html comments in your style tag. Comments in CSS are done like this:
<style type="text/css">
   body {
	  /* this is a comment */
   }
</style>



You have an else that returns true, followed by more else if's. This is your function:

function validateForm() {
	if(document.getElementById('fname').value=="" ) {
		alert("Please enter a First Name!");
		return false;
	}
	else if(document.getElementById('lname').value=="" ) {
		alert("Please enter a Last Name!");
		return false;
	}
	else {
		return true; 
	}
	}
	else if(document.getElementById('phone').value=="" ) {
		alert("Please enter a Phone Number!");
		return false;
	}
	else {
		return true; 
	}
}



This is correct:
function validateForm() {
	if(document.getElementById('fname').value=="" ) {
		alert("Please enter a First Name!");
		return false;
	}
	else if(document.getElementById('lname').value=="" ) {
		alert("Please enter a Last Name!");
		return false;
	}
	else if(document.getElementById('phone').value=="" ) {
		alert("Please enter a Phone Number!");
		return false;
	}
	else {
		return true; 
	}
}



Also, you have a spelling mistake on the first line of your javascript.
var frm=document.getElementEyId('myform');



Should be:
var frm=document.getElementById('myform');


This post has been edited by thehat: 03 March 2009 - 06:19 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1