[thelist] JavaScript and Form Validation Trickery Not Working

Syed Zeeshan Haider szh at hotpop.com
Sat Jun 8 08:26:03 CDT 2002


Hi Ben,
I have been trying to create such dynamic colour changes in my forms for
last many months. Like you, I also use JS and it's my observation that
Netscape Navigator is less cooperative with JS and CSS than Internet
Explorer, specially for this type of dynamic JS. I have some
JS-validated forms which do not work even with NN 6 at all but they work
with IE 5.5 very well.
Your JS will not work with NN 4 because of lack of support. This JS does
not work with Opera 6 also; I have tried it. For such situations, I
presume that "80% web surfers are IE users". So, we have to be
optimistic.
Hope this helps.
Syed Zeeshan Haider.
http://syedzeeshanhaider.faithweb.com/

----- Original Message -----
Date: Fri, 07 Jun 2002 14:52:17 -0500
To: thelist at lists.evolt.org
From: Ben Dyer <ben_dyer at imaginuity.com>
Subject: [thelist] JavaScript and Form Validation Trickery Not Working
Reply-To: thelist at lists.evolt.org

Let me preface this by saying my expertise in JavaScript is practically
nil.

I've been experimenting with the way I do form validation by changing
the
background color of fields that don't validate, like so:

   function verify_form() {

     error_color = '#FFD8D8';

     if (!document.forms[0].txtUsername.value) {
       alert("Please enter a username.");
       document.forms[0].txtUsername.focus();
       document.forms[0].txtUsername.style.backgroundColor =
error_color;
       return false;
     }

   }

And then on the form field:

<input type="text" name="txtUsername" id="txtUsername" size="15"
maxlength="15" value="" onchange="this.style.backgroundColor='white'" />

Now then, this correctly turns the field a shade of light red in IE5/6,
Netscape 6 but not in Netscape 4.  I expected it not to work in NN4,
that's
not the problem.  The problem is that Netscape 4, does the error
message,
focuses on the field, doesn't color it red but skips the return false;
line
and submits the form without any further validation.

Is there any way to fix this for NN4 without removing the color change?

--Ben

Ben Dyer, Senior Internet Developer, Imaginuity Interactive
http://www.imaginuity.com/

   Whatever it is, I'm sure that I was just about to get to it.
-----------------------------------------------------------------
   http://members.evolt.org/OKolzig37/     http://www.evolt.org/








More information about the thelist mailing list