I get the following error –
Error: phone.value is null or not an object
I bolded where it says the problem is. I guess I am confused as to why the error is occuring as similar code is on another page and works fine. I know the html code is not in depth but its just testing. The same error will occor on email.value. Any help would be appreciated.
My Code is –
<html>
<HEAD>
<script>
function submitIt(myForm) {
//check that fields are filled out
if (myForm.name.value == “”) {
alert(“You must enter a name”)
myForm.name.focus()
myForm.name.select()
return false
}
[B]if(!stringFilter(myForm.phone.value)){
alert(“Invalid phone number”)
myForm.phone.focus()
myForm.email.select()
return false
}
[B]if (!validEmail(myForm.email.value)) {
alert(“Invalid email address”)
myForm.email.focus()
myForm.email.select()
return false
}
function validEmail(email) {
invalidChars = ” /:,;”
if (email == “”) {
return false
}
for (i=0; i<invalidChars.length; i++) {
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) > -1) {
return false
}
}
atPos = email.indexOf(“@”,1)
if (atPos == -1) {
return false
}
if (email.indexOf(“@”,atPos+1) > -1) {
return false
}
periodPos = email.indexOf(“.”,atPos)
if (periodPos == -1) {
return false
}
if (periodPos+3 > email.length) {
return false
}
return true
}
}
function stringFilter (input)
{
s = input.value;
if (s == “”)
{
return false;
}
else
{
filteredValues = “()-+”; // Characters stripped out
var i;
var returnString = “”;
for (i = 0; i < s.length; i++)
{ // Search through string and append to unfiltered values to returnString.
var c = s.charAt(i);
if (filteredValues.indexOf(c) == -1) returnString += c;
}
// After stripping out (), -, or + checking to see if any characters exist. If so then fail and alert user
if(isNaN(returnString))
{
return false;
}
else
{
// Verifying that phone number is 10 digits or greater to be a valid phone number
if(returnString.length >= 10)
{
return true;
input.value = returnString;
}
else
{
return false;
}
}
}
}
</script>
</HEAD>
<BODY>
<form method=post action=”” onSubmit=””>
<input type=”text” size=”14″ maxlength=”14″ name=”name”>
<br>
<input type=”text” size=”14″ maxlength=”14″ name=”phone”>
<br>
<input type=”text” size=”14″ maxlength=”14″ name=”email”>
<br>
<input type=”button” value=”Submit” onClick=”return submitIt(this);”>
<input type=”reset” value=”Reset”>
</form>
</body>
</html>