473,748 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IE vs Firefox Javascript Validation Problem

4 New Member
Hi all

I'm a complete newbie to web development and Javascript especially. I've been creating a form for a webpage and have used a validation script gen_validatorv2 .js which I downloaded from the zip file referenced on http://www.javascript-coder.com/html...lidation.phtml

I managed to get everything working and was testing through Firefox that alerts were generated. However at the very end I thought I'd better check it was all ok on IE and found that the alerts aren't being generated at all.

The scenario is that I have a form with several fields to complete and I tested it by leaving some of the mandatory ones blank. When I click on submit, the alerts pop up in Firefox and prevent the form being submitted. In IE, I don't get any alerts popping up and the form doesn't submit either.

As I'm completely new, I really don't know where to start on this and my web searches haven't yet come up with anything. I am happy to post code to this thread, but am not sure where to start. If you experts are able to advise, I would be very grateful :) Are there any well known differences between how IE and Firefox handle Javascript?

Many thanks
cbs7
Apr 17 '07 #1
5 19077
Ansuiya
40 New Member
hi can u please post the code.
Apr 18 '07 #2
cbs7
4 New Member
Thanks for the reply :)

The webpage is quite long so I'll try and post the relevant bits

1. This is within the <head> </head> section

<script src="gen_valida torv2.js" type="text/javascript"></script>

2. To start the form I have

<form name="myform" method="post" action="Contact _Us_with_java_p 2.php" />

3. This performs the validation and comes just after the end of </form>

<script type="text/javascript">
var frmvalidator = new Validator("myfo rm");
frmvalidator.ad dValidation("Re asonForSale","r eq","Please select your Reason For Sale");
frmvalidator.ad dValidation("Wo uldLikeToSellAn dRentBack","req ","Please select if you would like to Sell and Rent Back");
frmvalidator.ad dValidation("Wa ntToSellWithin" ,"req","Plea se select How Quickly You Need to Sell");
frmvalidator.ad dValidation("Fi rstName","req", "Please enter your First Name");
frmvalidator.ad dValidation("La stName","req"," Please enter your Last Name");
frmvalidator.ad dValidation("Em ail","email","P lease enter a valid email address");
frmvalidator.se tAddnlValidatio nFunction("Chec kContactNumber" );
</script>

4. Below is the first part of the gen_validatorv2 .js code ( I need to post the 2nd part in another post as it is too long)

/*
-------------------------------------------------------------------------
JavaScript Form Validator
Version 2.0.2
Copyright 2003 JavaScript-coder.com. All rights reserved.
You use this script in your Web pages, provided these opening credit
lines are kept intact.
The Form validation script is distributed free from JavaScript-Coder.com

You may please add a link to JavaScript-Coder.com,
making it easy for others to find this script.
Checkout the Give a link and Get a link page:
http://www.javascript-coder.com/links/how-to-link.php

You may not reprint or redistribute this code without permission from
JavaScript-Coder.com.

JavaScript Coder
It precisely codes what you imagine!
Grab your copy here:
http://www.javascript-coder.com/
-------------------------------------------------------------------------
*/
function Validator(frmna me)
{
this.formobj=do cument.forms[frmname];
if(!this.formob j)
{
alert("BUG: couldnot get Form object "+frmname);
return;
}
if(this.formobj .onsubmit)
{
this.formobj.ol d_onsubmit = this.formobj.on submit;
this.formobj.on submit=null;
}
else
{
this.formobj.ol d_onsubmit = null;
}
this.formobj.on submit=form_sub mit_handler;
this.addValidat ion = add_validation;
this.setAddnlVa lidationFunctio n=set_addnl_vfu nction;
this.clearAllVa lidations = clear_all_valid ations;
}
function set_addnl_vfunc tion(functionna me)
{
this.formobj.ad dnlvalidation = functionname;
}
function CheckContactNum ber()
{
var frm = document.forms["myform"];
if (frm.ContactNum ber.value != frm.ConfirmCont actNumber.value )
{
alert ( "Contact Numbers Must Be Identical." );
return false;
}
else
{
return true;
}
}
function CheckPrivacyPol icyAgreement()
{
var frm = document.forms["myform"];
if (frm.PrivacyPol icyAgreement.ch ecked == false)
{
alert ( "Please tick the box to confirm you have read and agreed to our Privacy Policy." );
return false;
}
else
{
return true;
}
}
function clear_all_valid ations()
{
for(var itr=0;itr < this.formobj.el ements.length;i tr++)
{
this.formobj.el ements[itr].validationset = null;
}
}
function form_submit_han dler()
{
for(var itr=0;itr < this.elements.l ength;itr++)
{
if(this.element s[itr].validationset &&
!this.elements[itr].validationset. validate())
{
return false;
}
}
if(this.addnlva lidation)
{
str =" var ret = "+this.addnlval idation+"()";
eval(str);
if(!ret) return ret;
}
return true;
}
Apr 18 '07 #3
cbs7
4 New Member
2nd Part of gen_validatorv2 .js code
--------------------------------------------------

function add_validation( itemname,descri ptor,errstr)
{
if(!this.formob j)
{
alert("BUG: the form object is not set properly");
return;
}//if
var itemobj = this.formobj[itemname];
if(!itemobj)
{
alert("BUG: Couldnot get the input object named: "+itemname) ;
return;
}
if(!itemobj.val idationset)
{
itemobj.validat ionset = new ValidationSet(i temobj);
}
itemobj.validat ionset.add(desc riptor,errstr);
}
function ValidationDesc( inputitem,desc, error)
{
this.desc=desc;
this.error=erro r;
this.itemobj = inputitem;
this.validate=v desc_validate;
}
function vdesc_validate( )
{
if(!V2validateD ata(this.desc,t his.itemobj,thi s.error))
{
this.itemobj.fo cus();
return false;
}
return true;
}
function ValidationSet(i nputitem)
{
this.vSet=new Array();
this.add= add_validationd esc;
this.validate= vset_validate;
this.itemobj = inputitem;
}
function add_validationd esc(desc,error)
{
this.vSet[this.vSet.lengt h]=
new ValidationDesc( this.itemobj,de sc,error);
}
function vset_validate()
{
for(var itr=0;itr<this. vSet.length;itr ++)
{
if(!this.vSet[itr].validate())
{
return false;
}
}
return true;
}
function validateEmailv2 (email)
{
// a very simple email validation checking.
// you can add more complex email checking if it helps
if(email.length <= 0)
{
return true;
}
var splitted = email.match("^( .+)@(.+)$");
if(splitted == null) return false;
if(splitted[1] != null )
{
var regexp_user=/^\"?[\w-_\.]*\"?$/;
if(splitted[1].match(regexp_u ser) == null) return false;
}
if(splitted[2] != null)
{
var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
if(splitted[2].match(regexp_d omain) == null)
{
var regexp_ip =/^\[\d{1,3}\.\d{1,3 }\.\d{1,3}\.\d{ 1,3}\]$/;
if(splitted[2].match(regexp_i p) == null) return false;
}// if
return true;
}
return false;
}
function V2validateData( strValidateStr, objValue,strErr or)
{
var epos = strValidateStr. search("=");
var command = "";
var cmdvalue = "";
if(epos >= 0)
{
command = strValidateStr. substring(0,epo s);
cmdvalue = strValidateStr. substr(epos+1);
}
else
{
command = strValidateStr;
}
switch(command)
{
case "req":
case "required":
{
if(eval(objValu e.value.length) == 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : Required Field";
}//if
alert(strError) ;
return false;
}//if
break;
}//case required
case "maxlength" :
case "maxlen":
{
if(eval(objValu e.value.length) > eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : "+cmdvalue+ " characters maximum ";
}//if
alert(strError + "\n[Current length = " + objValue.value. length + " ]");
return false;
}//if
break;
}//case maxlen
case "minlength" :
case "minlen":
{
if(eval(objValu e.value.length) < eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : " + cmdvalue + " characters minimum ";
}//if
alert(strError + "\n[Current length = " + objValue.value. length + " ]");
return false;
}//if
break;
}//case minlen
case "alnum":
case "alphanumer ic":
{
var charpos = objValue.value. search("[^A-Za-z0-9]");
if(objValue.val ue.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+" : Only alpha-numeric characters allowed ";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1) +"]");
return false;
}//if
break;
}//case alphanumeric
case "num":
case "numeric":
{
var charpos = objValue.value. search("[^0-9]");
if(objValue.val ue.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+" : Only digits allowed ";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1) +"]");
return false;
}//if
break;
}//numeric
case "alphabetic ":
case "alpha":
{
var charpos = objValue.value. search("[^A-Za-z]");
if(objValue.val ue.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+" : Only alphabetic characters allowed ";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1) +"]");
return false;
}//if
break;
}//alpha
case "alnumhyphe n":
{
var charpos = objValue.value. search("[^A-Za-z0-9\-_]");
if(objValue.val ue.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+" : characters allowed are A-Z,a-z,0-9,- and _";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1) +"]");
return false;
}//if
break;
}
case "email":
{
if(!validateEma ilv2(objValue.v alue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+" : Enter a valid Email address ";
}//if
alert(strError) ;
return false;
}//if
break;
}//case email
case "lt":
case "lessthan":
{
if(isNaN(objVal ue.value))
{
alert(objValue. name+": Should be a number ");
return false;
}//if
if(eval(objValu e.value) >= eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : value should be less than "+ cmdvalue;
}//if
alert(strError) ;
return false;
}//if
break;
}//case lessthan
case "gt":
case "greatertha n":
{
if(isNaN(objVal ue.value))
{
alert(objValue. name+": Should be a number ");
return false;
}//if
if(eval(objValu e.value) <= eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : value should be greater than "+ cmdvalue;
}//if
alert(strError) ;
return false;
}//if
break;
}//case greaterthan
case "regexp":
{
if(objValue.val ue.length > 0)
{
if(!objValue.va lue.match(cmdva lue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+" : Invalid characters found ";
}//if
alert(strError) ;
return false;
}//if
}
break;
}//case regexp
case "dontselect ":
{
if(objValue.sel ectedIndex == null)
{
alert("BUG: dontselect command for non-select Item");
return false;
}
if(objValue.sel ectedIndex == eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+" : Please Select one option ";
}//if
alert(strError) ;
return false;
}
break;
}//case dontselect
}//switch
return true;
}
/*
Copyright 2003 JavaScript-coder.com. All rights reserved.
*/
Apr 18 '07 #4
cbs7
4 New Member
Hi there

Sorry I found that I had some html syntax causing the problem. Thanks for the help

cbs7
Apr 19 '07 #5
Ansuiya
40 New Member
hi i have not seen your code yet but if there is any error in your HTML as u hav already written then u can confirm it from validator about ur error.validator will show the error and line no. where the error occurred.check the html code using validator.
the site for validator is

validator.w3.or g
Apr 19 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3695
by: Dave Blair | last post by:
Hi, I have a problem with our intranet, we are planning to install Firefox instead of Internet Explorer onto some new PCs. However, we can't get the following JavaScript to work in Firefox and similar code is used in lots of the intranet stuff. The code should bring up a message box with a warning and not allow the user to continue unless they have filled in the entry in an html form (the form is called 'myauthor').
23
16141
by: Loony | last post by:
I have got a code like this in HTML section in ASP file which includes javascript file! The script works under MS IE but doesn't with Firefox! Can anybody tell me what is wrong? <HTML> <HEAD><TITLE></TITLE> <SCRIPT LANGUAGE="JavaScript" SRC="../inc/JSfile.js"><SCRIPT> <SCRIPT> <!-- other javascript scripts working propely
4
1430
by: Diffident | last post by:
Hello Guys, I am posting my weird experience on firefox by a piece of code I have written. That piece of code is supposed to be executed when the page is not posted back i.e., for the very first time. In IE, my code is doing what it is supposed to do i.e.., it is not executing that piece of code whenever page is posted back but in firefox browser it is executing even if it is a postback.
3
2093
by: TJS | last post by:
I am finding that the serverside requiredvalidator doesn't fire in the firefox browser, and user request proceeds through to my updateProfile method. Validation is working correctly in the IE browser. Anyone seen this problem or have any ideas why this might be occurring ?? (I have web.config browsercaps updated from http://slingfive.com/ ) code: =========
7
3589
by: Steve Murphy | last post by:
Do CustomValidators run on FireFox and Netscape? If not, how do you run a client-side script for field validation, submit the form to ASP.NET when is passes validation, and then do your server-side processing? Thanks in advance.
45
4746
by: Pat | last post by:
its seems asp.net validation doesn't fire when using FireFox? Tested a page and it doesn't fire. It seems the javascript doesn't fire Any ideas?
6
1830
by: goober | last post by:
Ladies & Gentlemen: I have built a form that client-side validates and posts data to a CRM beautifully in Internet Explorer (IE) 6. The problem comes in FireFox (FF) 1.5 when everything works except the validation. In FF it posts fine to my CRM but with no validation! Here are snippets of my code together after taking out as much as I can for brevity sake.
3
2611
rizwan6feb
by: rizwan6feb | last post by:
Hi experts! Recently i was working on "Form Validation Using Ajax". My form validation was creating problem, when a user changes focus too quickly. I had a post related to this, but was unable to solve the problem. Here is the previous post http://bytes.com/forum/thread798289.html Trying to trace the problem I have written a code (Separate from The Form Validation) which sends 300 requests with an interval of 10 miliseconds and displays the...
4
2112
by: =?Utf-8?B?RGF2ZSBXZWVkZW4=?= | last post by:
Hi, I seem to have found a bug in the regular expression validator under firefox 2.0.0.15 when I use saved form field values. Specifically I have an email address validator for a text box that uses the expression below. ^\s*(+\.)*+@(+\.)+{2,4}\s*$ When I first enter an email address such as a@b.com everything works as expected. On subsequent visits to the form, when I type the 'a' character
0
8822
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9528
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8235
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3298
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.