Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Dynamic assignment from array

Posted on 2004-09-21
Medium Priority
Last Modified: 2008-02-01
I have a form with text fields: note0, note1, note2, etc.  The number of these items will vary (i.e. sometimes just note0 and sometimes note0 to note100)

I have an array dataArray with the same number of items as the number of notes.

I would like to create a loop like this:

for(i=0; i < dataArray.length; i++){
    note + i.value = dataArray[i];

but of course there is a problem with "note + i.value".  Can anyone suggest how I can dynamically assign to a variable like this?
Question by:derekpapesch
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

viola123 earned 2000 total points
ID: 12119520
           <script language="javascript">
            function test(){
                  for(i=0; i < dataArray.length; i++){
                        document.getElementById("note" + i).value = dataArray[i];

            <INPUT id="note1" type="text" name="Text1"><br>
            <INPUT id="note2" type="text" name="Text2"><br>
            <INPUT id="note3" type="text" name="Text3"><br>
            <INPUT id="note4" type="text" name="Text4">


Author Comment

ID: 12119655

Thanks for your help Viola!

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question