I've written a piece of javascript that works fine in firefox but doesn't in IE:
Code:
<script type='text/javascript'>
function formValidation(){
var f_name = document.getElementById('f_name');
var s_name = document.getElementById('s_name');
var email = document.getElementById('email');
var comment = document.getElementById('comment');
if(isAlphabet(f_name, "Please enter a valid first name")){
if(isAlphabet(s_name, "Please enter a valid surname")){
[COLOR=red]if(madeSelection(age, "Please select an age category")){[/color]
if(emailValidator(email, "Please enter a valid email address: (username@example.com)")){
if(isEmpty(comment, "Please enter a comment")){
return true;
}
}
}
}
}
return false;
}
function isEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus();
return true;
}
return false;
}
function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
[COLOR=red]function madeSelection(elem, helperMsg){
if(elem.value == "choose"){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
[/color]
</script>
It's a contact form with validation so that the user enters the right information. In IE it doesn't seem to work from function madeSelection onwards.
I would be grateful if anyone could help me with this.
Thanks.