Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unsupported property of method error

Status
Not open for further replies.

programmher

Programmer
May 25, 2000
235
0
0
US
I am attempting to validate and substitute data for a phone number. If the user attempts to enter an area code other than the valid one, I need to change it. Here is my code:

<script>
function validate_PhoneNum(){
if (document.MyForm.PhoneNum.charAt(3)== &quot;000&quot;)
alert(&quot;strip 000 and use 123 instead&quot;)
return true
}
</script>

<form action=&quot;Myform.cfm&quot; name=&quot;MyForm&quot; id=&quot;MyForm&quot; enablecab=&quot;Yes&quot; onsubmit=&quot;return validate_PhoneNum(this.PhoneNum.value);&quot;><input type=&quot;text&quot; name=&quot;PhoneNum&quot; value=&quot;&quot;>
</form>

I keep getting &quot;object doesn't support this property or method&quot; error message. Why?

Second, what is the best method to change the &quot;000&quot; to &quot;123&quot;?


 
your passing a parameter but not receiving a parameter in the function
function validate_PhoneNum(){
_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
 
try this
I used the slice function to get the value of position 0 to 3 (area code) although you may want to validate that not having a space as in &quot; 123&quot;

<html>
<head>
<script>
function validate_PhoneNum(str){
alert(str);
var newStr = str.slice(0,3)
if (newStr == &quot;000&quot;) {
alert(&quot;strip 000 and use 123 instead&quot;)
return false;
} else {
return true
}
}
</script>
</head>
<body>
<form action=&quot;Myform.cfm&quot; name=&quot;MyForm&quot; id=&quot;MyForm&quot; enablecab=&quot;Yes&quot; onsubmit=&quot;return validate_PhoneNum(this.PhoneNum.value);&quot;>
<input type=&quot;text&quot; name=&quot;PhoneNum&quot; value=&quot;&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
</form>
</body> _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
 
on eother thing you could do if you want. the charAt function only returns the character at that position you refernce. so in your case you said 3 and if that character at position 3 was a then thats all you get.
so in order to do that with the charAt you need to due
charAt(0)
charAt(1)
charAt(2)

see how that would not be efficient _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
 
oh-ho-ho!!!

Now I see!!! Many thanks to all the responses!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top