Connecting Tech Pros Worldwide Help | Site Map

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

Phin
Guest
 
Posts: n/a
#1: Jul 23 '05
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

RobG
Guest
 
Posts: n/a
#2: Jul 23 '05

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


Phin wrote:[color=blue]
> 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![/color]

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
cosmic fool
Guest
 
Posts: n/a
#3: Jul 23 '05

re: HELP: 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.



Phin
Guest
 
Posts: n/a
#4: Jul 23 '05

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


Rob,

Thank you for your help.

I ended up using

setTimeout('test()',1000);

and it worked!

Thanks again!

Phin

Phin
Guest
 
Posts: n/a
#5: Jul 23 '05

re: HELP: 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

Evertjan.
Guest
 
Posts: n/a
#6: Jul 23 '05

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


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

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
Guest
 
Posts: n/a
#7: Jul 23 '05

re: HELP: 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:[color=blue]
> Phin wrote on 03 jun 2005 in comp.lang.javascript:
>[color=green]
> > What I am trying to do is rather long-winded and would take too much to
> > explain.
> > Please see my solution above.
> >[/color]
>
> There is nothing "above" in your posting.
>
> This is usenet, so always quote.
>
> --
> Evertjan.
> The Netherlands.
> (Replace all crosses with dots in my emailaddress)[/color]

Randy Webb
Guest
 
Posts: n/a
#8: Jul 23 '05

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


Phin wrote:[color=blue]
> 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.[/color]

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?
Closed Thread


Similar JavaScript / Ajax / DHTML bytes