This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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 . :)
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic