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.Solu tionEval.pwd.va lue ==
"")||(document. SolutionEval.pw d.value == null)){
alert("Please enter correct password")
document.Soluti onEval.pwd.focu s()
return false;
}
if (document.Solut ionEval.name.va lue == ""){
alert("Please enter your name")
document.Soluti onEval.name.foc us()
return false;
}
if (document.Solut ionEval.company .value == ""){
alert("Please enter your company name")
document.Soluti onEval.company. focus()
return false;
}
if (document.Solut ionEval.phone.v alue == ""){
alert("Please enter your phone number")
document.Soluti onEval.phone.fo cus()
return false;
}
if ((document.Solu tionEval.email. value ==
"")||(document. SolutionEval.em ail.value == null)){
alert("Please enter your email address")
document.Soluti onEval.email.fo cus()
return false;
}
/* check if the email address is valid */
if (echeck(documen t.SolutionEval. email.value)==f alse){
document.Soluti onEval.email.va lue=""
document.Soluti onEval.email.fo cus()
return false;
}
return true;
}
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf (at)
var lstr=str.length
var ldot=str.indexO f(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(do t)==-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(l at+1,lat+2)==do t){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(do t,(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.Solu tionEval.pwd.va lue ==
"")||(document. SolutionEval.pw d.value == null)){
alert("Please enter correct password")
document.Soluti onEval.pwd.focu s()
return false;
}
if (document.Solut ionEval.name.va lue == ""){
alert("Please enter your name")
document.Soluti onEval.name.foc us()
return false;
}
if (document.Solut ionEval.company .value == ""){
alert("Please enter your company name")
document.Soluti onEval.company. focus()
return false;
}
if (document.Solut ionEval.phone.v alue == ""){
alert("Please enter your phone number")
document.Soluti onEval.phone.fo cus()
return false;
}
if ((document.Solu tionEval.email. value ==
"")||(document. SolutionEval.em ail.value == null)){
alert("Please enter your email address")
document.Soluti onEval.email.fo cus()
return false;
}
/* check if the email address is valid */
if (echeck(documen t.SolutionEval. email.value)==f alse){
document.Soluti onEval.email.va lue=""
document.Soluti onEval.email.fo cus()
return false;
}
return true;
}
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf (at)
var lstr=str.length
var ldot=str.indexO f(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(do t)==-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(l at+1,lat+2)==do t){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(do t,(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>
Comment