Solved

Dynamic assignment from array

Posted on 2004-09-21
2
602 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

895 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

14 Experts available now in Live!

Get 1:1 Help Now