Solved

Function Works in IE but not NS

Posted on 2004-09-16
13
542 Views
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!
0
Comment
Question by:loureiro
  • 5
  • 3
  • 2
  • +3
13 Comments
 
LVL 13

Expert Comment

by:cLFlaVA
Comment Utility
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.
0
 
LVL 6

Accepted Solution

by:
viola123 earned 500 total points
Comment Utility
hi,

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

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


cheers
viola
0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
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?
0
 
LVL 3

Expert Comment

by:ragerino
Comment Utility
i think the problem is more the onSubmit-Event.

try calling your validation-function another way.

f.e.:
   - 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');">
</form>

----------------------------------------------------
  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
           ..............
        }else{
           //single value validation
           ..........
        }
     }
     if(wellValidated){
        //maybe you want to add the action to the form here else just do a "form.submit();"
        form.setAttribute('action','[yourAction]');
        setTimeout('document.getElementById("' + formID + '").submit();",50);
     }
  }
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Does this work in Netscape:

<html>
<head>
<style>
TH {
  text-align: right;
}
</style>
<script>
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]);
  }
  if(msg>""){
    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){
  if(theField.value.replace(/\s/g,"")==""){
    return "\nNo value entered for field: "+theLabel;
  } else {
    return "";
  }
}
function isAlpha(theField, theLabel){
  if(theField.value.replace(/[\s\w]/g,"")>""){
    return "\nNo valid value entered for field: "+theLabel;
  } else {
    return "";
  }
}
function isNumeric(theField, theLabel){
  if(theField.value.replace(/[\d\-\.\(\)]/g,"")>""){
    return "\nNo valid value entered for field: "+theLabel;
  } else {
    return "";
  }
}
function isEmail(theField, theLabel){
  if(!theField.value.match(/^\w+([\-\.]\w+)*\@\w+([\-\.]\w+)*\.[a-z]{2,3}$/i)){
    return "\nNo valid Email Address entered for field: "+theLabel;
  } else {
    return "";
  }
}

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

0
 
LVL 3

Expert Comment

by:ragerino
Comment Utility
nice regExp's zvonko :)
know a good book ???
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
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:
http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/regexp.html
http://msdn.microsoft.com/library/en-us/script56/html/js56jsgrpRegExpSyntax.asp

0
 
LVL 36

Expert Comment

by:Zyloch
Comment Utility
Even with all those manual stuff, it's hard to get it lol, at least for me.

Solutions
(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...




0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
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 ;-)
0
 
LVL 3

Expert Comment

by:ragerino
Comment Utility
@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
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Only one additional off topic: LotusScript is Beautiful!
(I am PCLP ;-)
0
 

Author Comment

by:loureiro
Comment Utility
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!
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
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/

Cheers,
Zvonko
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now