IE problem inserting rows & cells then setting colspan

Hi, i'm inserting rows and cells into a table dynamically using javascript and its working GREAT!!!

but the problem is i need the rows created to have an initial cell with no attrributes required then another cell with colspan=6, i could do this by innerHTML on the row but IE doesn't support this (please correct me if i'm wrong), second to this i could create a row then two cells in it, and then  use setAttribute on the secound cell to set the colspan, but IE doesn't seem to support this either :(

So if anyone can think of a solution to this other then creating all the rows initally and hiding them i'd be very greatful, i'm currently hiding them then displaying them but the resulting page is v.large.

Thanks
Dan
LVL 4
Dan_82Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
<html>
  <head>
    <script type="text/javascript">
  function addRow( aTab )
  {
    var tbl = document.getElementById( aTab ) ;
    var lastRow = tbl.rows.length;
    // if there's no header row in the table, then iteration = lastRow + 1
    var iteration = lastRow;
    var row = tbl.insertRow(lastRow);

    // left cell
    var cellLeft = row.insertCell( 0, 2 ) ;
    cellLeft.colSpan = 2 ;
    var textNode = document.createTextNode( 'Some text' );
    cellLeft.appendChild(textNode);

    // right cell
    var cellRight = row.insertCell( 1 ) ;
    textNode = document.createTextNode( 'Some text 2' );
    cellRight.appendChild(textNode);
  }
    </script>
  </head>
  <body>
    <table id="aTable" border="1">
      <tr><td>1</td><td>2</td><td>3</td>
    </table><br>
    <input type="button" onclick="addRow('aTable')" value="Add Row">
  </body>
</html>
0
TimYatesCommented:
Sorry:

<html>
  <head>
    <script type="text/javascript">
  function addRow( aTab )
  {
    var tbl = document.getElementById( aTab ) ;
    var lastRow = tbl.rows.length;
    // if there's no header row in the table, then iteration = lastRow + 1
    var iteration = lastRow;
    var row = tbl.insertRow(lastRow);

    // left cell
    var cellLeft = row.insertCell( 0 ) ;
    cellLeft.colSpan = 2 ;
    var textNode = document.createTextNode( 'Some text' );
    cellLeft.appendChild(textNode);

    // right cell
    var cellRight = row.insertCell( 1 ) ;
    textNode = document.createTextNode( 'Some text 2' );
    cellRight.appendChild(textNode);
  }
    </script>
  </head>
  <body>
    <table id="aTable" border="1">
      <tr><td>1</td><td>2</td><td>3</td>
    </table><br>
    <input type="button" onclick="addRow('aTable')" value="Add Row">
  </body>
</html>

Should do it :-)
0
TimYatesCommented:
Basically, after you create your cell with "insertCell", simple set the colSpan attribute...

ie:

  cellLeft.colSpan = 2 ;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.