[thelist] JavaScript and Form Validation Trickery Not Working

Karen J. Bowen karen at miinx.com.au
Mon Jun 17 01:33:01 CDT 2002


Ben Dyer wrote:
> Is there any way to fix this for NN4 without removing the color change?

Hi Ben,

Do object detection to bypass the non-supported code in NS4 browsers.

e.g.

function verify_form() {
   error_color = '#FFD8D8';
   if (!document.forms[0].txtUsername.value) {
     alert("Please enter a username.");
     document.forms[0].txtUsername.focus();

     // **** insert oject checking here ****
     if (document.forms[].elements[].style) {
       document.forms[0].txtUsername.style.backgroundColor = error_color;
     }
     return false;
   }

}


I think that should work... or maybe you could check for
doc.getElementById in the same spot, which NS4 also would not go for.

Then in your html element, change your 'onchange' code to a function,
and again use object detection.

e.g.
<input type="text" name="txtUsername" id="txtUsername" size="15"
maxlength="15" value="" onchange="return chgBack()" />

and create new function:
function chgBack() {
   if (document.getElementById) {
     this.style.backgroundColor='white'
   }
}

hth,
Karen




More information about the thelist mailing list