Solved

Dynamic assignment from array

Posted on 2004-09-21
2
600 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
Comment Utility
           <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
Comment Utility
Beautiful.

Thanks for your help Viola!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now