Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

beginner can't find source of error 1

Status
Not open for further replies.

RobBroekhuis

Technical User
Oct 15, 2001
1,971
US
I'm new to JavaScript, and can't figure out what's causing my problem. I have the following piece of html document:
Code:
<table width=100%><tr><td><h1>Welcome new user!</h1></td><td align=right><img src=&quot;hpslogosmall.gif&quot;></td></tr></table>   Joining the forum is easy.  Just enter your username and password below,
   along with your e-mail address.  The username will be how you are known to
   forum users.  Unless you feel uncomfortable doing so, I suggest you use your
   actual name.  The information in the first section can be seen by all
   forum users; the information in the second section is only to facilitate
   your use of the forum, and cannot be viewed by anyone else.
      <script language=&quot;JavaScript&quot;>
   function pwdOK() {
      var frm=window.document.NewUser;
      var OK=true;
      if (frm.username.value.length<4) {
         alert(&quot;Username too short.  Please enter one with at least 4 characters.&quot;);
         frm.username.focus(); OK=false;}  (*ERROR HERE*)
      if (OK && !isNum(frm.donorcode.value) {
         alert(&quot;Donorcode must be numeric (or left blank).&quot;); 
         frm.donorcode.select(); OK=false;}
      if (OK && frm.pwd.value.length<4) {
         alert(&quot;Please enter a password with at least 4 characters.&quot;);
         frm.pwd.value=&quot;&quot;; frm.pwd2.value=&quot;&quot;; frm.pwd.focus();
         OK=false;}
      if (OK && frm.pwd.value!=frm.pwd2.value) {
         alert(&quot;The two passwords you entered were not identical.  Please try again&quot;);
         frm.pwd.value=&quot;&quot;; frm.pwd2.value=&quot;&quot;; frm.pwd.focus();
         OK=false;}
      return OK;
   }
   </script>
This generates an error in IE upon loading the page, indicating &quot;expecting a (&quot; on the line I marked above. The page then continues to load, and executes just fine. The function isn't called until the form is submitted, which works OK. What's my problem?


Rob
[flowerface]
 
You have the following (just below your coment about an error):

Code:
if (OK && !isNum(frm.donorcode.value) {

All will work if you change it to (note the ) that was added near the end of the line to balance your braces):

Code:
if (OK && !isNum(frm.donorcode.value)) {

All the best,
Jeff
 
Ah - I'm truly embarrassed now. Thanks for setting me straight. I'm still a little confused as to why IE would point me to the line BEFORE the error. I understand parsers sometimes don't find an error until AFTER it occurs, but BEFORE seems odd. Does IE start the line count at 0 rather than 1?


Rob
[flowerface]
 
The pb doesn't seem to be at the line u mark but the line under.
U wrote :
if (OK && !isNum(frm.donorcode.value) {
and U forget a ')' after your isNum test.
Try :
if (OK && !isNum(frm.donorcode.value)) {

and normally, it would be ok (I test it and I got no error)

by
 
oups, sorry, i was writing an answer and during this, I don't see the answer was still here ! ;o)
 
It doesn't specifically count from 0 I don't think.

Maybe it reports the error line incorrectly because of the way it is parsing the line? If it updates the lineCount (the line number) for each line when it has successfully parsed it, then if it encounters an error it would report the error as being on the last successfully parsed line.

Just a thought. I have no idea. I only use the line numbers offered in debugging as a guide at the best of times.

Jeff
 
OK. At any rate, thanks for your help. I should know better... [blush]

Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top