Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Javascript: Help with error
Old 09-13-2007, 09:04 AM Javascript: Help with error
Junior Talker

Posts: 1
Name: Marc Frail
Trades: 0
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
}

if(!stringFilter(myForm.phone.value)){
alert("Invalid phone number")
myForm.phone.focus()
myForm.email.select()
return false
}

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>
mfrail is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-13-2007, 09:22 AM Re: Javascript: Help with error
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
You're passing a reference to the button, not the form.
Quote:
Originally Posted by mfrail View Post
onClick="return submitIt(this)
Should be
Code:
 onclick="return submitIt(this.form)
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Javascript: Help with error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43908 seconds with 12 queries