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
Solved

Dynamic assignment from array

Posted on 2004-09-21
2
604 Views
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?
0
Comment
Question by:derekpapesch
2 Comments
 
LVL 6

Accepted Solution

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

            </script>
      </head>
      <body>
            <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">
      </body>



regards
viola
0
 
LVL 4

Author Comment

by:derekpapesch
ID: 12119655
Beautiful.

Thanks for your help Viola!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

860 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