• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing the text inside the first TextBox , the last div gets updated

 
Roshan Khandelwal
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue is
1) On a WebPage using Javascript , dynamically creating elements .
2) The page initially has a parent Division
3) The code loops 10 times .

4) In each loop , the code creates one new input Box with a new Id [ inputid + i (loop counter) ] and add it to a parent Division .

5) A new division is created , with a new id [ id + i ] and add it to the parent division , with the innerHTML value of id + i .

6) Add a function to the text box which on change updates the innerHTML value of coressponding div [ or at least is expected to ]


However , with this code , when i change the text inside the first TextBox [ or for that reason any other textBox ] , the last div gets updated .

My understanding was that the inner div would be attached to the correct textBox . So changing the first text would update the first div and so on .
Please help .

Entire Code attached for reference :



Pretty sure , someone else would have faced the same issue . If someone could point to the right thread .
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the The Infamous Loop Problem section: http://robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/

Eric
 
Roshan Khandelwal
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great Link... Thanks a TON!!!

It not only solves my doubt but also is so much more enlighting . :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic