Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-13-2003, 11:02 PM   PM User | #1
Phényx
New to the CF scene

 
Join Date: Jan 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Phényx is an unknown quantity at this point
Question document.write(string) so why not div.write(string) ?

Hi !

I've created a labelled <div> section, and want to know if there is a javascript command to write something in the <div> section (like the document.write(string) command does to the wole document)

thx ;-)
Phényx is offline   Reply With Quote
Old 01-13-2003, 11:19 PM   PM User | #2
chrismiceli
Regular Coder

 
Join Date: Sep 2002
Location: Louisiana
Posts: 576
Thanks: 0
Thanked 0 Times in 0 Posts
chrismiceli is an unknown quantity at this point
give the div an id
<div id="divid"></div>
<script type="text/javascript">
document.getElementById("divid").innerHTML = "hi";
</script>
you could also put html in the div just like you could w/ document.write();
__________________
DevEdge - MSDN - DevGuru
chrismiceli is offline   Reply With Quote
Old 01-15-2003, 12:04 PM   PM User | #3
Phényx
New to the CF scene

 
Join Date: Jan 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Phényx is an unknown quantity at this point
Thumbs up Thanks ! I found the code

Thanks !

Your code is great but try this one :
It works both on IE and Mozilla

<script>
function WriteDiv(text, id) {

if (document.getElementById) {
x = document.getElementById(id);
x.innerHTML = '';
x.innerHTML = text;
}
else if (document.all) {
x = document.all[id];
x.innerHTML = text;
}
}
</script>
Phényx is offline   Reply With Quote
Old 01-15-2003, 12:30 PM   PM User | #4
Borgtex
Regular Coder

 
Join Date: Aug 2002
Location: Spain
Posts: 420
Thanks: 0
Thanked 0 Times in 0 Posts
Borgtex is an unknown quantity at this point
Simplified, assuming that it's IE or Mozilla:

<script>
function WriteDiv(text, id)
{
x = document.all?document.all[id]:document.getElementById(id);
x.innerHTML = text;
}
</script>
__________________
Don't resist to assimilation. Billions of Borgs can't be wrong!
Borgtex is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:30 PM.


Advertisement
Log in to turn off these ads.