Results 1 to 15 of 15

Thread: Write to a DIV

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    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?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Write to a DIV

    HTML Code:
     function showsubmenu(linkmode)
       {
       	document.getElementById('querysubmenu').write('ha');
      	document.getElementById('querysubmenu').style.display = 'block';
      
      }
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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';  
     }
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Write to a DIV

    You must create all the elements using the createElement function and instert text using the createTextNode function.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: Write to a DIV

    Bah. F this. I'm going to do it using PHP.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Write to a DIV

    Quote 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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  11. #11

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: Write to a DIV

    How recently have all the browsers began using it?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  13. #13

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    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.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  14. #14
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Write to a DIV

    Quote 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?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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
  •  



Click Here to Expand Forum to Full Width