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

P

Phin

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
 
C

cosmic fool

if you post the minimum amount of code
in which it still fails, someone here can try
and figure out what the problem is.
 
R

RobG

Phin said:
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'.
 
P

Phin

Rob,

Thank you for your help.

I ended up using

setTimeout('test()',1000);

and it worked!

Thanks again!

Phin
 
P

Phin

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
 
E

Evertjan.

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.
 
P

Phin

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
 
R

Randy Webb

Phin said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top