[Javascript] Loop problem

Muchacho, Laurent (TWIi London) LMuchacho at twii.net
Tue Mar 18 07:48:49 CST 2003


Stop everyone

This is pretty simple 

when you do your loop throw a form you can simply do 

for (var i=0;i<document.formsName.length;i++){
	if(document.formsName.elements[i].name!=''){
		alert(document.formsName.elements[i].name);
	}
}

this will alert the name value of each element in your form are not empty

Laurent 

ps: this link might help
http://developer.netscape.com/docs/manuals/js/client/jsref/index.htm 

click on table of content at the top of the main frame



-----Original Message-----
From: Chris Tifer [mailto:christ at saeweb.com]
Sent: 18 March 2003 13:38
To: javascript at LaTech.edu
Subject: Re: [Javascript] Loop problem


 From the looks of it, this would never loop:

> for (i=1;i=<%=Numfrm%>;i++)

Should their be some of of comparison, such as:

<  or <= or > or >= or ==

When you say " var1 = var2", you're automatically setting
var1 to var2's values. == checks for equality.  That'd be where
I started to debug.

Chris Tifer

----- Original Message -----
From: "Alexandre Zglav" <azglav at heritage.ch>
To: <javascript at LaTech.edu>
Sent: Tuesday, March 18, 2003 7:44 AM
Subject: [Javascript] Loop problem


> Hello all.
>
> I quite new to javascript and I have a problem with a loop and I just cant
> find a solution to it on the internet.
>
> I am trying to validate a for m with a variable amount of fields.
>
> Here is the code i am using :
>
>
> <!--
>
> function CheckForm(form1) {
>
>         var why ="";
>
>         for (i=1;i=<%=Numfrm%>;i++)
>                 why += checkName(form1.name[i].value);
>                 if ( why != "") {
>                         alert(why);
>                         return false;
>                 }
>
> }
>
>
> function checkName (strng) {
>         var error = "";
>
>         //test of the filling
>         if (strng == "") {
>                 error = "you didn' enter a username. \n";
>         }
>         return error;
> }
>
>
> -->
>
> Note that <%=Numfrm%> is a the variable i am retrieving from ASP. It
> returns me an integer value chosen in an earlier field.
>
> Now my problem is at this point :
>
> why += checkName(form1.name[i].value);
>
> It seems that [i] is not accepted as I always get an error at this level
> in my script debugger.
>
> Can someone help me with this ?
>
> Thanks in advance.
>
> Best regards.
> _____________________________________
> IT Projects
> Alexandre Zglav
> Heritage Finance and Trust Company
> 12 cours des bastions
> 1205 Geneva
> Switzerland
> Phone :  ++ 41 22 817 31 68
> ----------------------------------------------------------------
> This document should only be read by those persons to whom it is
> addressed  and  is  not intended to be relied upon by any person
> without  subsequent written confirmation of its contents. If you
> have  received  this  e-mail message in error, please destroy it
> and delete it from your computer.
> Any  form of  reproduction, dissemination, copying,  disclosure,
> modification,  distribution  and/or  publication  of this E-mail
> message is strictly prohibited.
> ----------------------------------------------------------------
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


DISCLAIMER - The preceding e-mail message (including any attachments)
contains information that may be confidential, may be protected by the
attorney-client or other applicable privileges, or may constitute non-public
information.  It is intended to be conveyed only to the designated
recipient(s) named above.  If you are not an intended recipient of this
message, or have otherwise received it in error, please notify the sender by
replying to this message and then delete all copies of it from your computer
system.  Any use, dissemination, distribution, or reproduction of this
message by unintended recipients is not authorized and may be unlawful. The
contents of this communication do not necessarily represent the views of
this company.



More information about the Javascript mailing list