Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [js noob] appendChild problems in ie

    i'm trying to generate a calendar using dom to create a table. it works in firefox and opera, but ie won't show it, and sometimes gives me an alert saying it can't display the page, and then shows a 404 page. here's the code
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <meta name="generator" content="PSPad editor, www.pspad.com">
      <title>testing calendar generation</title>
      <script type="text/javascript">
        function printcal(){
            var calItem = document.getElementById('dynamicTable');
            for(var i=0;i<5;i++){
                var tablerow = document.createElement("tr");
                for(var j=0;j<7;j++){
                    var tablecell = document.createElement("td");
                    var celldata = document.createTextNode(i+''+j);
                    tablecell.appendChild(celldata);
                    tablerow.appendChild(tablecell);
                }
                calItem.appendChild(tablerow);
            }
        }
      </script>
      </head>
      <body>
        <p>Senectus vel accumsan eleifend in laoreet interdum orci nec vitae Sed.
         Wisi felis Integer justo Suspendisse euismod et ornare laoreet tempus Morbi.
          Dignissim sed libero Lorem congue ut ipsum In id et leo. Ut amet neque hac
           Nam lacinia cursus non Nunc a congue. Nibh Phasellus Sed enim vel nec.</p>
           <table id='dynamicTable'>
           <script type="text/javascript">
            printcal();
           </script></table>
        <p>Sit tellus facilisis pulvinar congue In Nam ut facilisis est pede. Sem Sed
         leo accumsan velit orci eget Vivamus Curabitur cursus et. Turpis id hac tempus
          et mauris suscipit nulla id id eu. Tempor dui lacus nibh sapien tellus
           semper egestas a Sed tempus. Habitant accumsan Vestibulum eget ut Nam 
           leo pretium vitae gravida fringilla. Tellus nulla vel hendrerit interdum
            Aenean laoreet quis dui adipiscing Sed. Vivamus.</p>
    
      </body>
    </html>
    i want it to write a table into the dynamictable element. any suggestions? thanks

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would be better if you used a window.onload event handler function to call printcal() instead of placing that script element in the table like that.

    I suspect that you need to append the rows to the <tbody> instead of the <table>.

    After
    Code:
            var calItem = document.getElementById('dynamicTable');
    add
    Code:
            if(calItem.getElementsByTagName && calItem.getElementsByTagName('tbody').length) {
                    calItem = calItem.getElementsByTagName('tbody')[0];
            }
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yup, i just needed a tbody for the rows to go in. i found that in another thread on here just a few minutes ago too.

    thanks for the tip about window.onload, hadn't thought about using that.

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    window.onload and appendChild and IE have some problems. On complex pages that take a while for certain things to happen, you can actually cause a naster bug that will stop IE from loading the page until you restart the browser.

    You might find it better to use window.onreadystatechange if you run into this problem. I would try it out, and if you can get the onreadystatechange to work use it, because users with slower machines could run into problems when you try to appendChild if IE isn't ready.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •