Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Function Works in IE but not NS

Posted on 2004-09-16
Medium Priority
Last Modified: 2008-01-09
I'm having problems with my javascript. It works fine in NS but it doesnt work at all in IE. Here is what my call looks like:

<form name="addcustomer" method="post" action="" onSubmit="return validateAddCustomer(addcustomer.principleFirstName,addcustomer.principleLastName,addcustomer.principleEmail,addcustomer.secondaryFirstName,addcustomer.secondaryLastName,addcustomer.secondaryEmail,addcustomer.street,addcustomer.city,addcustomer.province,addcustomer.postal,addcustomer.homePhone,addcustomer.numOfChildren);">

now i know its a problem with the call cause it works fine in netscape...it could also be a problem in the way i call my javascript page, as follows:

<script src="java/main.js" type="text/javascript"></script>

any help would be much appreciated!
Question by:loureiro
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3
LVL 13

Expert Comment

ID: 12081076
We'll be able to help more if you show us the code for the validateAddCustomer() function.

The error most likely lies in your function, where a line of code works for Netscape browsers only.

Accepted Solution

viola123 earned 1500 total points
ID: 12081270

don't forget to specify the script language,even for a js file

<script language="JavaScript" src="java/main.js" type="text/javascript"></script>

LVL 36

Expert Comment

ID: 12081380
I must say the call looks pretty correct. It could be a Netscape only line in your function (since it's surprising it doesn't work on IE but WILL work on Netscape...) Possibly a browser check even though I don't know why in a validating function.

As to the language="javascript", type="text/javascript" alone should do it, and it's actually more recommended than language="javascript", but with IE, who knows?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 12081864
i think the problem is more the onSubmit-Event.

try calling your validation-function another way.

   - don't use a submit-button.
   - use instead of it a normal button with onclick="validateCustomer(...);"
   - if validation works ok, then call the submit in the function document.forms[0].submit(); (i assume that it's your only form)
   - what about a from action (the url you want to submit the form)
   - you are also giving lots of parameters to the function instead of this try something like this

<form id="addcustomer" method="post" action="" >
<!-- your form elements go here -->
<input type="button" value="Submit" onclick="validateCustomer('addcustomer');">

  function validateCustomer(formID){
     var form=document.getElementById(formID);
     var wellValidated=true;    //if something goes wrong -> wellVAlidated=false
     for(var i=0;i<form.elements.length;i++){
        var element=form.elements[i];
        if (element.type=='select' || element.type='checkbox' || element.type=='radio'){
           //multiple values validation (radio just has one value, but
           //single value validation
        //maybe you want to add the action to the form here else just do a "form.submit();"
        setTimeout('document.getElementById("' + formID + '").submit();",50);
LVL 63

Expert Comment

ID: 12081893
Does this work in Netscape:

TH {
  text-align: right;
var chkFields = [
['principleFirstName','First Name', [isNotEmpty, isAlpha]],
['principleLastName','Last Name', [isNotEmpty, isAlpha]],
['principleEmail','Email Address', [isNotEmpty, isEmail]],
['secondaryFirstName','Second First Name', [isNotEmpty, isAlpha]],
['secondaryLastName','Second Last Name', [isNotEmpty, isAlpha]],
['secondaryEmail','Second Email Address', [isNotEmpty, isEmail]],
['street','Street', [isNotEmpty, isAlpha]],
['city','City', [isNotEmpty, isAlpha]],
['province','Province', [isNotEmpty, isAlpha]],
['postal','ZIP', [isNotEmpty, isNumeric]],
['homePhone','Phone Number', [isNotEmpty, isNumeric]],
['numOfChildren','Number of Children', [isNotEmpty, isNumeric]]];
function validateAddCustomer(theForm){
  var msg = "";
  for(var i=0;i<chkFields.length;i++){
    msg += checkField(theForm, chkFields[i]);
    alert("Folowing errors found:"+msg+"\n\nPlease correct the errors and try again.");
    return false;
  } else {
    return true;
function checkField(theForm, fieldEntry){
  var fldMsg = "";
  theField = theForm[fieldEntry[0]];
  for(var i=0;i<fieldEntry[2].length;i++){
    fldMsg += fieldEntry[2][i](theField, fieldEntry[1]);
  return fldMsg;
function isNotEmpty(theField, theLabel){
    return "\nNo value entered for field: "+theLabel;
  } else {
    return "";
function isAlpha(theField, theLabel){
    return "\nNo valid value entered for field: "+theLabel;
  } else {
    return "";
function isNumeric(theField, theLabel){
    return "\nNo valid value entered for field: "+theLabel;
  } else {
    return "";
function isEmail(theField, theLabel){
    return "\nNo valid Email Address entered for field: "+theLabel;
  } else {
    return "";

<form name="addcustomer" method="post" action="" onSubmit="return validateAddCustomer(this);">
<tr><th>First Name:</th><td>
<input type=text name="principleFirstName">
<tr><th>Last Name:</th><td>
<input type=text name="principleLastName">
<tr><th>Email Address:</th><td>
<input type=text name="principleEmail">
<tr><th>Secondary First Name:</th><td>
<input type=text name="secondaryFirstName">
<tr><th>Secondary Last Name:</th><td>
<input type=text name="secondaryLastName">
<tr><th>Secondary Email Address:</th><td>
<input type=text name="secondaryEmail">
<input type=text name="street">
<input type=text name="city">
<input type=text name="province">
<input type=text name="postal">
<tr><th>Phone Number:</th><td>
<input type=text name="homePhone">
<tr><th>Number of Children:</th><td>
<input type=text name="numOfChildren">
<input type=submit>


Expert Comment

ID: 12081987
nice regExp's zvonko :)
know a good book ???
LVL 63

Expert Comment

ID: 12082625
Book? You cannot learn RegExp trough reading. All you need is a reference card for all the cryptic meta characters.
But problem with reference cards is that they has not to be overloaded and has to meet your visual taste.
Here some examples:

LVL 36

Expert Comment

ID: 12082678
Even with all those manual stuff, it's hard to get it lol, at least for me.

(1) Buy a Perl book. There's bound to be a huge section on there.
(2) Experiment over and over again, in which case you probably won't have time for EE, being exhausted and overloading your brain from frustration.
(3) Pretend regex's don't exist. You can get by just right without them and using Javascript string functions quite extensively and creatively
(4) Achieve great success to change regular expressions so only you understand them then charge people for you to write their regex's
(5) Post here and let other experts do the work

Of course, there's other stuff you can do, but I'm getting off topic here, heh

Like the other experts said above, it could be too many parameters...

LVL 63

Expert Comment

ID: 12082744
My recommendation is Zyloch's item (2): Do it again and again until Frustration changes to deep Satisfaction about the esthetical beauty of the expressions ;-)

Expert Comment

ID: 12082782
@zvonko: thanx for your links. and a question in a language which you maybe understand (odakle si ti moja privatna electronska adressa je moj nik u ovome forumu i nag gmx.net)

@zyloch: i've experimented with regular expressions, but i use them not often, because i'm also developing lotusscript. and lotusscript is horror.
now we are moving to java and j2ee and i think it will be good to use regexp's there.

now enough with regexp's
we should not become off-topic
LVL 63

Expert Comment

ID: 12082829
Only one additional off topic: LotusScript is Beautiful!
(I am PCLP ;-)

Author Comment

ID: 12098798
zvonko very nice code however i had to give the points to viola123. quick easy solution to my problem! very weird how it didnt recognize it!
thanks to everyone who helped me out!
LVL 63

Expert Comment

ID: 12099982
No problem.
But my problem is when I see grading B or worse.
Give grading B only if you get disappointed by experts after several requests for clarification.
The expert points are multiplicity of the grading and do not cost you extra.
If you want to do viola a favor, then ask Community Support to correct your grading to Excellent!
Here the link for the change request: http://www.experts-exchange.com/Community_Support/


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question