javascript

U

uso

hello, how can i write a text on web page with javascript:

like in PHP <? echo "bla_bla_bla"?>


<script language="javascript" type="text/javascript">
print 'bla_bla_bla';
</script>
 
U

Ulrik Skovenborg

uso said:
hello, how can i write a text on web page with javascript:

In javascript you use document.write():
<script type="text/javascript">
document.write("blablalbal");
</script>
 
U

uso

In javascript you use document.write():
<script type="text/javascript">
document.write("blablalbal");
</script>

thx. but it writes the blablabla in new , how to write it in the sam web
page
 
U

Ulrik Skovenborg

uso said:
thx. but it writes the blablabla in new , how to write it in the sam web
page

Yes the problem with document.write is that it only works as you may
expect before the whole page is loaded (and the DOM Tree is still to be
completed). That's why document.write and print (in PHP) works pretty
much the same way and are only used when generating the page.

To add text to the page after the page is loaded is another problem.
There are several ways to accomplish this but one of the easist one is
to use the innerHTML-property that every HTML-element has:

document.getElementById("elementID").innerHTML = "TExt";
or
document.body.innerHTML += "text"; // adds the text directly to the
body-element

You shouldn't try this method before the whole page is loaded though.
The element you try to add the text to might not be comlete yet.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sun, 29 May
thx. but it writes the blablabla in new , how to write it in the sam web
page

Read FAQ 4.15 for that.

Please use a properly informative Subject line.

For proper quoting when using Google for News :-
Keith Thompson wrote in comp.lang.c, message ID
<[email protected]> :-
If you want to post a followup via groups.google.com, don't use
the "Reply" link at the bottom of the article. Click on "show
options" at the top of the article, then click on the "Reply" at
the bottom of the article headers.

Since that is what the experts in this newsgroup prefer to read, it will
be to your advantage to comply.
 
R

RobG

Ulrik Skovenborg wrote:
[...]
document.getElementById("elementID").innerHTML = "TExt";
or
document.body.innerHTML += "text"; // adds the text directly to the
body-element

You shouldn't try this method before the whole page is loaded though.
The element you try to add the text to might not be comlete yet.

Replacing the body.innerHTML will have pretty much the same effect as
using document.write() - the current content will be obliterated.

Much better to use DOM methods to create the required elements and
append them to appropriate nodes. innerHTML, though widely supported,
is not a W3C standard and is most useful for replacing the content of
an element with some other (reasonably simple) content.

To the OP: research 'createElement'.

<URL:http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-2141741547>

<URL:http://www.mozilla.org/docs/dom/domref/dom_doc_ref.html#998664>

<URL:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndude/html/dude100499.asp>
 

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

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top