HELP: document.getElementById("test").innerHTML only works with an alert!

Discussion in 'Javascript' started by Phin, Jun 2, 2005.

  1. Phin

    Phin Guest

    Hi,

    I am tring to update some text in a div statement via

    document.getElementById("test").innerHTML = "data loaded!"

    and

    <div id="test">
    Loading ... please hold!
    </div>

    It only updates the text if I include an alert("some message")
    statement after the "document.getElementById" line. So, after the alert
    comes up and I press the button to close the alert message box, the
    text updates!

    This is really strange! How can I force this text to update?
    I appreciate your help!

    Thanks,

    Phin
     
    Phin, Jun 2, 2005
    #1
    1. Advertising

  2. Phin

    cosmic fool Guest

    Re: document.getElementById("test").innerHTML only works with an alert!

    if you post the minimum amount of code
    in which it still fails, someone here can try
    and figure out what the problem is.
     
    cosmic fool, Jun 2, 2005
    #2
    1. Advertising

  3. Phin

    RobG Guest

    Re: HELP: document.getElementById("test").innerHTML only works withan alert!

    Phin wrote:
    > Hi,
    >
    > I am tring to update some text in a div statement via
    >
    > document.getElementById("test").innerHTML = "data loaded!"
    >
    > and
    >
    > <div id="test">
    > Loading ... please hold!
    > </div>
    >
    > It only updates the text if I include an alert("some message")
    > statement after the "document.getElementById" line. So, after the alert
    > comes up and I press the button to close the alert message box, the
    > text updates!
    >
    > This is really strange! How can I force this text to update?
    > I appreciate your help!


    This generally happens if you run the script before the element is
    actually loaded in the document - the alert gives the document time to
    finish loading so it works then.

    Try running the script onload, or put it just after the div 'test'.


    --
    Rob
     
    RobG, Jun 3, 2005
    #3
  4. Phin

    Phin Guest

    Rob,

    Thank you for your help.

    I ended up using

    setTimeout('test()',1000);

    and it worked!

    Thanks again!

    Phin
     
    Phin, Jun 3, 2005
    #4
  5. Phin

    Phin Guest

    Re: document.getElementById("test").innerHTML only works with an alert!

    CF,

    What I am trying to do is rather long-winded and would take too much to
    explain.
    Please see my solution above.

    Thank you!

    Phin
     
    Phin, Jun 3, 2005
    #5
  6. Phin

    Evertjan. Guest

    Re: document.getElementById("test").innerHTML only works with an alert!

    Phin wrote on 03 jun 2005 in comp.lang.javascript:

    > What I am trying to do is rather long-winded and would take too much to
    > explain.
    > Please see my solution above.
    >


    There is nothing "above" in your posting.

    This is usenet, so always quote.

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Jun 3, 2005
    #6
  7. Phin

    Phin Guest

    Re: document.getElementById("test").innerHTML only works with an alert!

    In regards to Evertjan's post:

    For those of you that are not viewing this via google groups, here is
    how I solved my problem.

    I included the following line:

    setTimeout('test()',1000);

    //test() is the procedure that I call that does the
    document.getElementById("test").innerHTML

    Actually, setTimeout('test()',100); worked for me.


    Thanks,

    Phin

    Evertjan. wrote:
    > Phin wrote on 03 jun 2005 in comp.lang.javascript:
    >
    > > What I am trying to do is rather long-winded and would take too much to
    > > explain.
    > > Please see my solution above.
    > >

    >
    > There is nothing "above" in your posting.
    >
    > This is usenet, so always quote.
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Replace all crosses with dots in my emailaddress)
     
    Phin, Jun 3, 2005
    #7
  8. Phin

    Randy Webb Guest

    Re: document.getElementById("test").innerHTML only works with analert!

    Phin wrote:
    > In regards to Evertjan's post:
    >
    > For those of you that are not viewing this via google groups, here is
    > how I solved my problem.


    Had you read this groups FAQ before posting, you would have never asked
    this question as it is covered either in the FAQ or in its links. But
    that aside, the group FAQ also covers quoting and top-posting.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Answer:It destroys the order of the conversation
    Question: Why?
    Answer: Top-Posting.
    Question: Whats the most annoying thing on Usenet?
     
    Randy Webb, Jun 3, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lawrence
    Replies:
    3
    Views:
    197
  2. wk
    Replies:
    5
    Views:
    170
    Dietmar Meier
    Apr 22, 2005
  3. Replies:
    6
    Views:
    264
  4. Martin
    Replies:
    3
    Views:
    150
  5. Replies:
    4
    Views:
    166
    Jonas Raoni
    Nov 21, 2006
Loading...

Share This Page