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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE compatibility 1

Status
Not open for further replies.

juvesteve

Programmer
Jan 2, 2008
19
GB


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.

 
You haven't defined the [tt]age[/tt] variable.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
Hey juvesteve, since you're fairly new to the site you may have overlooked the MVP ranking system.

Since dwarfthrower was kind enough to provide you with a helpful solution, why not click the link labeled:

[purple]*[/purple] Thank dwarfthrower
for this valuable post!

This will give him a purple star next to his post and also a vote for the tipmaster of the week. It's a nice gesture towards all the posters that provide you with help here on the site.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top