Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Validate with Netscape 4.7


Message #1 by Nestor Rueda <nestor92@y...> on Mon, 20 Jan 2003 11:54:17 -0800 (PST)
As Chris said.
It should be this line for all browsers (IE too):

var tempobj=3D d.elements[formElems[i]];

/Robert


-----Original Message-----
From: Chris Scott [mailto:chris@e...]
Sent: Monday, January 20, 2003 9:30 PM
To: javascript
Subject: [javascript] Re: Validate with Netscape 4.7


Hi Nestor,

> I have a simple form with alot of fields and I want to validate only a

> few of them. I'm using the following javascript but it is not working
> for Netscape 4.7. Any idea what I'm doing wrong?
>
> Thanks in advance.
>
>
> <script language=3D"javascript" TYPE=3D"text/javascript">
> <!--
> function checkFormStaff(d)
> {
> var missedFields =3D "";
> var msg;
> var formElems =3D new Array
> ('LastName','FirstName','Region');
> var formNames =3D new Array('Last Name','First
> Name','Zone');
>
>
> // check for empty fields in the form 
for(i=3D0;i<formElems.length;i++){
>
> if(document.layers){
>            //thisbrowser=3D"NN4";

change this line...

>            var tempobj=3DformElems[i];

for...

var tempobj=3Dd[formElems[i]];

>         }
>         if(document.all){
>             //thisbrowser=3D"ie"
>    var tempobj=3Dd.elements(formElems[i]);
>         }
>         if(!document.all && document.getElementById){
>             //thisbrowser=3D"NN6";
>    var tempobj=3D d.elements[formElems[i]];
>         }
> if ((tempobj.value =3D=3D '') || (tempobj.value =3D=3D ' ')
> || (tempobj.selectedIndex=3D=3D0)) { missedFields +=3D "\t"
> + formNames[i] + " \n"; }
> }
>
>
> if (missedFields !=3D "") {
>    msg =3D  "The following required field(s) are empty
> :\n\n" + missedFields + "\n";
>    alert(msg);
>    return false;
> }
> else document.user.submit();
> }
> //-->
> </script>
>
> <form name=3D"user" action=3D"validate.asp" method=3D"post">
>
> <table border=3D"0" cellPadding=3D"1" cellSpacing=3D"1" width=3D"75%">
>   <tr>
>     <td>Zone</td>
>     <td><select id=3D"Region" name=3D"Region">
> <option value=3D"">- Select Zone -</option>
> <option value=3D"1"> Region 1</option>
> <option value=3D"2"> Region 2</option>
> <option value=3D"3"> Region 3</option>

Insert the following line here...

</select>

>     </td>
>   </tr>
>   <tr>
>     <td>&nbsp;</td>
>     <td>&nbsp;</td></tr>
>   <tr>
>     <td>Last Name</td>
>     <td><input id=3D"LastName" name=3D"LastName" Value=3D""></td></tr>
>   <tr>
>     <td>First Name</td>
>     <td><input id=3D"FirstName" name=3D"FirstName"
> Value=3D""></td></tr>
> </table>
>
> <P align=3Dright><input type=3D"button" value=3D"Continue"
> name=3D"ValidateFields" onClick=3D"javascript:return
> checkFormStaff(this.form);"> </p>
>
> </form>

In addition, IMHO I think it would be cleaner to place the following
within the form tag...

onsubmit=3D"return checkFormStaff(this);"

& then just use a standard submit button e.g....

<input type=3D"submit" value=3D"Continue">

HTH,

Chris






  Return to Index