Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through variable enumerated field names

Status
Not open for further replies.

ABF

Technical User
Aug 9, 2005
3
US
I am attempting to loop through a set of field names that are enumerated by another loop ...IE fieldName1, fieldName2, fieldName3

The code I wrote:

for (var c=1; c<document.form2.HMANY.value; c++) {
if (document.form2.txtUserName.value == &quot;&quot;) {
missinginfo += &quot;\n - Name&quot;;
}

where &quot;HMANY&quot; is the value passed from the previous form to enumerate the fields in in another loop. In this loop txtUserName is the enumerated field name. I thought adding +c to the name would resolve this, but it does not return the message.
 
&quot;I thought adding +c to the name would resolve this,&quot; --> can you be more precise please, it's not ver clear (at least to me !) ? what is the problem to be solved ? and i don't see any +c ??
 
I left the +c out of the name to show the original script. This is what I was trying to use:

for (var c=1; c<document.form2.HMANY.value; c++) {
if (document.form2.txtUserName +c.value == &quot;&quot;) {
missinginfo += &quot;\n - Name&quot;;
}

The field I am trying to validate is created in a VBScript loop as follows:

<TD><INPUT NAME = &quot;txtUserName<%= intLoop%>&quot; TYPE=&quot;TEXT&quot; SIZE=&quot;27&quot;></TD>
<TD><INPUT NAME = &quot;txtSSN<%= intLoop%>&quot; MAXLENGTH=&quot;9&quot; TYPE=&quot;TEXT&quot; SIZE=&quot;9&quot;></TD>
<TD><INPUT NAME = &quot;txtCostCenter<%= intLoop%>&quot; TYPE=&quot;TEXT&quot; SIZE=&quot;27&quot;></TD>
<TD><INPUT NAME = &quot;txtRollupCode<%= intLoop%>&quot; TYPE=&quot;TEXT&quot; SIZE=&quot;27&quot;></TD>
<TD><SELECT id=select1 Name=&quot;selApplicationRequested<%= intLoop%>&quot; style=&quot;HEIGHT: 22px; WIDTH: 220px&quot;>
<OPTION>--Choose An Application--
<OPTION>Time Admin
<OPTION> WRMS
<OPTION>Labor Reports
<OPTION>Time Admin and WRMS
<OPTION>Time Admin and Labor Reports
<OPTION>WRMS and Labor Reports
</SELECT></TD>
 
ok !!! you have an element which name looks like &quot;NameNumber&quot; !!
i would eval the value of the string
something like :
s=&quot;document.form2.txtUserName&quot;+c+&quot;.value&quot;;
if (eval(s)==&quot;&quot;)
{...
 
Thank you!!! That answer solved my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top