Hi,

Please take a look at the below javascript that I use to validate a form (the form is located at http://www.targetwebsites.co.uk/contact.html 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.background Color = 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.background Color = '';
}else{
debugTxt += 'You need a container element for the group: '+ el.group +' (for element: '+ el.name +')\n';
}
}
}