T
TAM
Hi,
I have a simple JavaScript code that ensures that all the form fields
are filled and there is also a function that checks if the email is a
valid address. For some reason IE is giving "Object Expected" error on
the alert statement. The same code doesn't give an error in NN or
Opera or Mozilla or FireFox.
Can someone give me a clue as what could be wrong here?
Thanks,
joe
<script language = "JavaScript">
function validate(){
if ((document.SolutionEval.pwd.value ==
"")||(document.SolutionEval.pwd.value == null)){
alert("Please enter correct password")
document.SolutionEval.pwd.focus()
return false;
}
if (document.SolutionEval.name.value == ""){
alert("Please enter your name")
document.SolutionEval.name.focus()
return false;
}
if (document.SolutionEval.company.value == ""){
alert("Please enter your company name")
document.SolutionEval.company.focus()
return false;
}
if (document.SolutionEval.phone.value == ""){
alert("Please enter your phone number")
document.SolutionEval.phone.focus()
return false;
}
if ((document.SolutionEval.email.value ==
"")||(document.SolutionEval.email.value == null)){
alert("Please enter your email address")
document.SolutionEval.email.focus()
return false;
}
/* check if the email address is valid */
if (echeck(document.SolutionEval.email.value)==false){
document.SolutionEval.email.value=""
document.SolutionEval.email.focus()
return false;
}
return true;
}
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 ||
str.indexOf(at)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 ||
str.indexOf(dot)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}
if (str.substring(lat-1,lat)==dot ||
str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID") << This where IE gives error "Object
Expected"
return false
}
return true
}
</script>
I have a simple JavaScript code that ensures that all the form fields
are filled and there is also a function that checks if the email is a
valid address. For some reason IE is giving "Object Expected" error on
the alert statement. The same code doesn't give an error in NN or
Opera or Mozilla or FireFox.
Can someone give me a clue as what could be wrong here?
Thanks,
joe
<script language = "JavaScript">
function validate(){
if ((document.SolutionEval.pwd.value ==
"")||(document.SolutionEval.pwd.value == null)){
alert("Please enter correct password")
document.SolutionEval.pwd.focus()
return false;
}
if (document.SolutionEval.name.value == ""){
alert("Please enter your name")
document.SolutionEval.name.focus()
return false;
}
if (document.SolutionEval.company.value == ""){
alert("Please enter your company name")
document.SolutionEval.company.focus()
return false;
}
if (document.SolutionEval.phone.value == ""){
alert("Please enter your phone number")
document.SolutionEval.phone.focus()
return false;
}
if ((document.SolutionEval.email.value ==
"")||(document.SolutionEval.email.value == null)){
alert("Please enter your email address")
document.SolutionEval.email.focus()
return false;
}
/* check if the email address is valid */
if (echeck(document.SolutionEval.email.value)==false){
document.SolutionEval.email.value=""
document.SolutionEval.email.focus()
return false;
}
return true;
}
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 ||
str.indexOf(at)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 ||
str.indexOf(dot)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}
if (str.substring(lat-1,lat)==dot ||
str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID") << This where IE gives error "Object
Expected"
return false
}
return true
}
</script>