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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Field question

Status
Not open for further replies.
Aug 4, 2003
12
0
0
US
I have fields define based on an input number, for example if user keys in 5 then the fields are defined as field1, field2, field3, field4, and field5. There are other fields defined too in the form. Is there are way to access these fields 1 - 5 in javascript by using something like form.field+i.value where i is a variable running in a loop based on that input number. Any help would be appreciated. The number could go to 50 so I do not want to check each field separately.

Thanks
 
You can use something like:
Code:
for (var fi=1;fi<=lastfieldnumber;fi++)
  {
  var fieldvalue = document.forms['formnamehere'].elements['fieldnamehere' + fi].value;
  //work with field value here
  }

You'd have to set the lastfieldnumber either in a Javascript variable somewhere on the page, or add a hidden input with the value and then refer to that to get the number.

Lee
 
Thank you for such a quick response. I was using the same loop but was trying form.fieldname+1.value. The max number is stored in a variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top