Jump to content

Simple validation script works in all browsers I tested except IE6


sKunKbad

Recommended Posts

Honestly, javascript is not my strength, so I'm hoping somebody will point out what is wrong very easily. When I go to my contact form in IE6, I can not type in the fields.

 

My form has an onkeyup event in the form's open tag.

 

The script that checks 3 form fields is this:

 

function validate(){
var realname=document.getElementById("rn").value
var email=document.getElementById("addy").value
var mesg=document.getElementById("mesg").value
var nameIsGood = 'no'
var emailIsGood = 'no'

var myNameRegex = /^[a-z\s'-]*$/i;
var matchPos1 = realname.search(myNameRegex);
if (realname != ''){
	if (matchPos1 != -1) {
		document.getElementById("name-status").style.color = '#66cc66'
		nameIsGood = 'yes'
	}else{
		document.getElementById("name-status").style.color = '#ff0000'
		nameIsGood = 'no'
	}
}else{
	document.getElementById("name-status").style.color = '#ff0000'
	nameIsGood = 'no'
}

var myEmailRegex = /^(?:^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|gov|mobi|tv|biz|info|jobs|museum|edu)$)$/i;
var matchPos2 = email.search(myEmailRegex);
if (email != ''){
	if (matchPos2 != -1) {
		document.getElementById("email-status").style.color = '#66cc66'
		emailIsGood = 'yes'
	}else{
		document.getElementById("email-status").style.color = '#ff0000'
		emailIsGood = 'no'
	}
}else{
	document.getElementById("email-status").style.color = '#ff0000'
	emailIsGood = 'no'
}


var myMesgRegex = /<+|>+/;
var matchPos3 = mesg.search(myMesgRegex);
if (mesg != ''){
	if (matchPos3 == -1 && nameIsGood == 'yes' && emailIsGood == 'yes'){
		document.getElementById("button").disabled = ''
		document.getElementById("notags").innerHTML = ''
	}else if (matchPos3 != -1){
		document.getElementById("button").disabled = 'disabled'
		document.getElementById("notags").innerHTML = 'Error: No < or > symbols allowed in message body!'
	}else{
		document.getElementById("button").disabled = 'disabled'
		document.getElementById("notags").innerHTML = 'Either your name or email address is not valid!'
	}
}else{
	document.getElementById("button").disabled = 'disabled'
	document.getElementById("notags").innerHTML = '* All Form Fields Are Required !'
}

}

 

If you'd like to see what I'm working on in action, go to my website www.brianswebdesign.com, and then go to /test/kohana/contact.php . Sorry, I broke the link in 2 because I don't want to have the link indexed.

 

Thanks for any help.

Link to comment
Share on other sites

function validate(){
   var realname=document.getElementById("rn").value;
   var email=document.getElementById("addy").value;
   var mesg=document.getElementById("mesg").value;
   var nameIsGood = 'no';
   var emailIsGood = 'no';

   var myNameRegex = /^[a-z\s'-]*$/i;
   var matchPos1 = realname.search(myNameRegex);
   if (realname !== ''){
      if (matchPos1 !== -1) {
         document.getElementById("name-status").style.color = '#66cc66';
         nameIsGood = 'yes';
      }else{
         document.getElementById("name-status").style.color = '#ff0000';
         nameIsGood = 'no';
      }
   }else{
      document.getElementById("name-status").style.color = '#ff0000';
      nameIsGood = 'no';
   }

   var myEmailRegex = /^(?:^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|gov|mobi|tv|biz|info|jobs|museum|edu)$)$/i;
   var matchPos2 = email.search(myEmailRegex);
   if (email !== ''){
      if (matchPos2 !== -1) {
         document.getElementById("email-status").style.color = '#66cc66';
         emailIsGood = 'yes';
      }else{
         document.getElementById("email-status").style.color = '#ff0000';
         emailIsGood = 'no';
      }
   }else{
      document.getElementById("email-status").style.color = '#ff0000';
      emailIsGood = 'no';
   }

   
   var myMesgRegex = /<+|>+/;
   var matchPos3 = mesg.search(myMesgRegex);
   if (mesg !== ''){
      if (matchPos3 == -1 && nameIsGood == 'yes' && emailIsGood == 'yes'){
         document.getElementById("button").disabled = '';
         document.getElementById("notags").innerHTML = '';
      }else if (matchPos3 !== -1){
         document.getElementById("button").disabled = 'disabled';
         document.getElementById("notags").innerHTML = 'Error: No < or > symbols allowed in message body!';
      }else{
         document.getElementById("button").disabled = 'disabled';
         document.getElementById("notags").innerHTML = 'Either your name or email address is not valid!';
      }
   }else{
      document.getElementById("button").disabled = 'disabled';
      document.getElementById("notags").innerHTML = '* All Form Fields Are Required !';
   }

}

Link to comment
Share on other sites

The problem was with my installation of multiple IEs after installing IE8. I haven't tried to reinstall multiple IEs yet, but will try tonight when I get home. If multiple IEs' IE6 doesn't work after reinstalling, it could mean the end of IE6 support for me. I don't know what other developers do, but it isn't in my budget to have another computer at home, just to run IE6. Yes, I could run a virtual installation of XP on my ubuntu, and it would have IE6, but my computer is dual boot, and it would suck to have to reboot anytime I want to see something in IE6. The browsers in Firefox never seem to have issues, so I don't go to that side when I'm working.

Link to comment
Share on other sites

We rarely get clients bitching about IE6 incompatibility at the company I work for.  But, my dept isn't really far enough up on the totem pole to tell them so the hell what, so we usually do have to cater to it when it comes up.  Some of us use

 

http://www.xenocode.com/Browsers/

 

Some of us use

 

http://www.microsoft.com/downloads/details.aspx?FamilyID=8e6ac106-525d-45d0-84db-dccff3fae677&displaylang=en

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.