Reloading an HTML element populated by Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mofmans2ndcoming
    New Member
    • Nov 2007
    • 16

    Reloading an HTML element populated by Javascript

    First, let me thank acoder for his/her help with my last javascript problem.

    I have a new problem though.

    I have a simple form that uses selection boxes and I wanted the boxes to be smart. As I have said before, I do not have access to the server side system so I have to add the smarts on the client side.

    it is simple, month day year.

    I have the months set as static HTML with values from 0 to 11 accordingly. I have set the page to run my "fillDay()" function onload, which proceeds to properly fill in the correct number of days for the month.... January being the one that is set at the start.

    The "Days" select box is populated through appendChild() calls. The problem arises when I go to change the month. when fillDay runs again, it continues to append to the initial list rather than simple replace the items.

    I have tried code that should remove the child nodes first:

    Code:
    while(slctDay.hasChildNodes()){
                    slctDay.removeChild(slctDay.firstChild);
    but it did not remove the appended elements.

    What can I do to remedy this? is there a way to reload a single element on the page?

    Thanks,

    Jeremy
  • mofmans2ndcoming
    New Member
    • Nov 2007
    • 16

    #2
    I figured it out (why is it always the very next page in google after you post a question that gives you an answer?)

    Code:
    while(slctDay.childNodes[0]){
      slctDay.removeChild(slctDay.childNodes[0]);}
    I attempted this with a for loop and an iterator but it resulted in a hard crash of my browser. I wondered why until I realized, as it removed the nodes, the indexes of the remaining nodes changed so when I got half way through I buffer overflowed the array and it crashed the browser.

    Comment

    Working...