Forum Moderators: open

Message Too Old, No Replies

Form Validate not Working in FF but ok in IE

         

edsseo

12:49 pm on Dec 11, 2008 (gmt 0)

10+ Year Member



Hi,

Please take a look at the below javascript that I use to validate a form (the form is located at <snipped> and click on the form)

It works fine in IE but i cannot get it to work in firefox. Anyone any ideas why?

Below code is called in form with this code:
<form action="thankyou.php" method="post" class="quickenquiry" onsubmit="return validateForm(this)">

Javascript Code:

var groups = new Object();
var debugTxt = '';
function validateForm(it){
debugTxt = '';
var bad = 0;
for (i in groups){
groups[i] = 0;
}
for (var i=0; i<it.elements.length; i++){

var loopbad = 0;
var el = it.elements[i];
if (el.validate == 'notempty' && el.value == ''){
loopbad = 1;
}else if (el.validate == 'email' && !el.value.match(/^[\w\d\.\_\-\']+@[\w\d\.\-]+\.[\w]+$/)){
loopbad = 1;
}else if (el.validate == 'custom' && !el.value.match(el.regexp)){
loopbad = 1;
}else if (el.validate == 'checkbox' && !el.checked){
loopbad = 1;
}else{
if (el.validate){
debugTxt += 'The validation type: '+ el.validate +' is unknown (for element: '+ el.name +')\n'
}
markGood(el);
}
if (el.group && loopbad == 1){
if (groups[el.group] == 1){
loopbad = 0;
markGood(el)
}else{
markBad(el);
}
}
if (loopbad == 1 && !el.group){
markBad(el)
bad =1;
}
}
for (i in groups){
if (groups[i] == 0){
bad = 1;
}
}

if (debug == 1){
if (debugTxt != ''){
alert('DEBUG OUTPUT\n\n'+debugTxt);
}else{
alert('DEBUG MODE IS ON\nRemember to disable it before releasing to the wild ;)')
}
}
if (bad == 1){
alert(errorText);
return false;
}
}
function markBad(el){
if (el.group){
if (groups[el.group] != 1){
groups[el.group] = 0;
}
if (document.getElementById(el.group)){
document.getElementById(el.group).style.backgroundColor = badGrpCol
}else{
debugTxt += 'You need a container element for the group: '+ el.group +' (for element: '+ el.name +')\n';
}
}else{
el.style.backgroundColor = badCol;
}
}
function markGood(el){
el.style.backgroundColor = '';
if (el.group){
groups[el.group] = 1;
if (document.getElementById(el.group)){
document.getElementById(el.group).style.backgroundColor = '';
}else{
debugTxt += 'You need a container element for the group: '+ el.group +' (for element: '+ el.name +')\n';
}
}
}

[edited by: coopster at 2:50 pm (utc) on Dec. 11, 2008]
[edit reason] no personal urls please TOS [webmasterworld.com] [/edit]

MichaelBluejay

5:49 pm on Dec 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi, and welcome to Webmaster World.

I'm afraid you're probably not going to get much help with this one.

(1) You didn't say what the problem is. "Doesn't work" isn't a description of the problem. A proper description is, "When I do X, then Y happens."

(2) That is far too much code for anyone to want to look over.

(3) Basic troubleshooting is to start off with the *simplest*, shortest version that works, even if it's as simple as running an alert(); or document.write(); message. From there keep adding code until it fails, and then you'll know where the problem was. And if you can't get even a short, simple script to work, then you can post the *short, simple* script here, and someone will help you.