JavaScript validering i IE - wtf?
Ja jeg fik aldrig rigtig svar sidst da jeg stillede dette spørgsmål (http://eksperten.dk/spm/676212), så nu prøver jeg igen:Hvorfor virker følgende JavaScript form valideringsscript ikke i IE (det virker perfekt i Firefox)?
Det er 3 funktioner: 1) checker at alle obligatoriske felter er udfyldt, 2) validerer e-mail og 3) validerer password.
Her er koden:
<script language = "Javascript">
function ValidatePw(theForm){
if (theForm.pw.value.length < 4) {
alert("Password must as a minimum be 4 characters long!");
theForm.pw.focus();
return false;
}
if (theForm.pw.value != theForm.pw2.value){
alert("Passwords doesnt match!");
theForm.pw2.focus();
return false;
}
return true;
}
/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
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")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail")
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail")
return false
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail")
return false
}
return true
}
function ValidateEmail(){
var emailID=document.userreg.email
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email!")
emailID.focus()
return false
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return ValidatePw(userreg);
}
function ValidateForm(theForm) {
if ((theForm.name_f.value != '') && (theForm.name_f.value != '') && (theForm.birth_d.value != 'Day') && (theForm.birth_m.value != 'Month') && (theForm.birth_y.value != 'Year') && (theForm.phone.value != '') && (theForm.phone.value != '+') && (theForm.country.value != '') && (theForm.country.value != '-- Country --') && (theForm.school_name.value != '') && (theForm.school_city.value != '') && (theForm.school_country.value != '') && (theForm.school_country.value != '-- Country --') && (theForm.school_phone.value != '') && (theForm.school_con.value != 'Write shortly how you are connected to the above school/institution (ex. as a teacher, student or parent).')){
return ValidateEmail();
}else{
alert('You need to fill out all of the mandatory (*) fields!');
return false
}
}
</script>
<form action="<?=$pagenext;?>" method="post" name="userreg" onSubmit="return ValidateForm(userreg)">
.... osv ...
</form>
Jeg er ikke så stiv i JavaScript, så er der ikke please nogen som kan hjælpe?
