PDA

View Full Version : Form validating in Netscape?



colette
Nov 27th, 2003, 03:38 PM
Hi all, me again, but with a simple one this time (i hope) ;) ,

I've got a form in a web page, in which I have used some regular expressions on some fields to validate and on a couple of others just straight forward javascript to ensure the field isn't left blank.

It works fine in IE but when I view it in Netscape the reg exp fields work fine but the fields that just ensure it's not empty seem to be just skipped over? There are no error messages, it just ignores those lines.

My question is, is there particular coding I could use so Netscape doesn't ignore these fields?

My present code for one of the problem fields is:

if ((form.DeliveryAddress.value) == false) {
alert("Please enter an address for delivery of your order. You can't complete your order without it.");
form.DeliveryAddress.focus();
form.DeliveryAddress.select();
return false;
}

all the validating codes are called in a simple onSubmit function within the form tag.

Many thanks in advance.

Colette
:thumbsup:

glenngv
Nov 27th, 2003, 03:49 PM
if your form name is "form", avoid using such name, it might cause unexpected error. and you must use absolute reference to the form:

document.formNameHere.DeliveryAddress.value

not just formNameHere.DeliveryAddress.value which IE allows. :rolleyes:

anyway, here's how to fix it:

function validate(objForm){
...
if (objForm.DeliveryAddress.value == "") {
alert("Please enter an address for delivery of your order. You can't complete your order without it.");
objForm.DeliveryAddress.focus();
objForm.DeliveryAddress.select();
return false;
}
...
}
...
<form name="form1" onsubmit="return validate(this)">

colette
Nov 27th, 2003, 04:36 PM
Hi Glenn,

Thanks alot for the very quick response. I did as you suggested, but without creating a new function (I just put it as part of the function I already had) and it works :D , hoorah!

Again, many many thanks.

Colette
:thumbsup: