|
-
Jan 20th, 2005, 11:11 AM
#1
Thread Starter
Frenzied Member
Write to a DIV
I'm trying to dynamically write some links to a div element and then show it and I'm not having much luck:
Code:
function showsubmenu(linkmode)
{
document.getElementById('querysubmenu').write('ha');
document.getElementById('querysubmenu').style.display = 'block';
}
It doesn't like me doing the write but the display portion works. I've read on the net that this is hard to do, but couldn't find a solid description of how to get it accomplished. I may end up just reloading the page and doing it with PHP, but I was hoping there was a simple solution to this.
Help?
-
Jan 20th, 2005, 11:56 AM
#2
Re: Write to a DIV
HTML Code:
function showsubmenu(linkmode)
{
document.getElementById('querysubmenu').write('ha');
document.getElementById('querysubmenu').style.display = 'block';
}
-
Jan 20th, 2005, 12:46 PM
#3
Thread Starter
Frenzied Member
Re: Write to a DIV
Ok... you didn't change anything??!
Either way, I found the answer on another forum. I'm using innerHTML instead of write.
-
Jan 20th, 2005, 12:50 PM
#4
Re: Write to a DIV
I don't know what happened there??? I gave you the code and an explanation. Don't use innerHTML, its IE only. This will working in IE,NS and FF.
HTML Code:
function showsubmenu(linkmode)
{
var div = document.getElementById('querysubmenu');
var p = docoument.createElement('p');
p.appendChild(document.createTextNode('hello'));
div.appendChild(p);
document.getElementById('querysubmenu').style.display = 'block';
}
-
Jan 20th, 2005, 12:57 PM
#5
Thread Starter
Frenzied Member
Re: Write to a DIV
Ok, that works except for the fact that it is not using any HTML that I put in it. It just spits everything to the browser.
-
Jan 20th, 2005, 01:04 PM
#6
Re: Write to a DIV
You must create all the elements using the createElement function and instert text using the createTextNode function.
-
Jan 20th, 2005, 01:05 PM
#7
Thread Starter
Frenzied Member
Re: Write to a DIV
Bah. F this. I'm going to do it using PHP.
-
Jan 20th, 2005, 01:19 PM
#8
Re: Write to a DIV
 Originally Posted by ober0330
Bah. F this. I'm going to do it using PHP.
Who says you can't have a div which is invisible containing the HTML. Then when you need it use Javascript to make it appear.
PHP is probably better. It means its truely cross browser then.
-
Jan 20th, 2005, 01:21 PM
#9
Thread Starter
Frenzied Member
Re: Write to a DIV
Yeah... I'm doing the hide/unhide thing now. I'm wasting far too much time on such a trivial detail.
-
Jan 21st, 2005, 05:25 PM
#10
Re: Write to a DIV
While innerHTML once was IE-only, all browsers implement it now. It should be noted that there are some bugs in IE's implementation.
Not that I recommend its use - it doesn't work in true XHTML pages, for example.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 24th, 2005, 07:52 AM
#11
Thread Starter
Frenzied Member
Re: Write to a DIV
How recently have all the browsers began using it?
-
Jan 24th, 2005, 07:55 AM
#12
Re: Write to a DIV
I think Opera since 6, Mozilla since somewhere pre-1.0. NN4 doesn't support it.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 24th, 2005, 07:57 AM
#13
Thread Starter
Frenzied Member
Re: Write to a DIV
Ok... thanks for that. I probably still won't use it, since some of my users on the intranet are Netscape fans. And I've completed the workaround for this problem anyways.
-
Jan 24th, 2005, 08:52 AM
#14
Re: Write to a DIV
 Originally Posted by CornedBee
While innerHTML once was IE-only, all browsers implement it now. It should be noted that there are some bugs in IE's implementation.
Not that I recommend its use - it doesn't work in true XHTML pages, for example.
It doesn't appear work in Firefox 
Why was innerHMTL not taken up by the W3C committee. Is it because it didn't conform with the whole XML hierarchy stuff with nodes and all?
-
Jan 24th, 2005, 08:55 AM
#15
Re: Write to a DIV
Because innerHTML writes markup in an actual language. The DOM is supposed to be independent of the markup language behind it. (That is, it need not be HTML or XML, it could be anything you invent as long as it follows the same general idea of hierarchic nested elements.) Thus, having real markup inside the DOM is against the spirit of the standard.
I'm 100% sure it works in Firefox. Try this page:
http://stud3.tuwien.ac.at/~e0226430/innerHtmlQuirk.html
It's my documentation of a bug in IE's innerHTML implementation.
Last edited by CornedBee; Jan 24th, 2005 at 09:00 AM.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|