Click to See Complete Forum and Search --> : Write to a DIV
ober0330
Jan 20th, 2005, 10:11 AM
I'm trying to dynamically write some links to a div element and then show it and I'm not having much luck:
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?
visualAd
Jan 20th, 2005, 10:56 AM
function showsubmenu(linkmode)
{
document.getElementById('querysubmenu').write('ha');
document.getElementById('querysubmenu').style.display = 'block';
}
ober0330
Jan 20th, 2005, 11:46 AM
Ok... you didn't change anything??!
Either way, I found the answer on another forum. I'm using innerHTML instead of write.
visualAd
Jan 20th, 2005, 11:50 AM
:eek: 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.
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';
}
ober0330
Jan 20th, 2005, 11:57 AM
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.
visualAd
Jan 20th, 2005, 12:04 PM
You must create all the elements using the createElement function and instert text using the createTextNode function.
ober0330
Jan 20th, 2005, 12:05 PM
Bah. F this. I'm going to do it using PHP.
visualAd
Jan 20th, 2005, 12:19 PM
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.
ober0330
Jan 20th, 2005, 12:21 PM
Yeah... I'm doing the hide/unhide thing now. I'm wasting far too much time on such a trivial detail. :rolleyes:
CornedBee
Jan 21st, 2005, 04:25 PM
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.
ober0330
Jan 24th, 2005, 06:52 AM
How recently have all the browsers began using it?
CornedBee
Jan 24th, 2005, 06:55 AM
I think Opera since 6, Mozilla since somewhere pre-1.0. NN4 doesn't support it.
ober0330
Jan 24th, 2005, 06:57 AM
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.
visualAd
Jan 24th, 2005, 07:52 AM
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 :confused:
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?
CornedBee
Jan 24th, 2005, 07:55 AM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.