Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
author
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great Link... Thanks a TON!!!

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