If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Form Validate not Working in FireFox but ok in IE

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-12-08, 06:03
edsseo edsseo is offline
Registered User
 
Join Date: Dec 2008
Posts: 2
Form Validate not Working in FireFox but ok in IE

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';
}
}
}
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On