Dynamic Table Creation, colspan issue.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • william_dean
    New Member
    • May 2006
    • 2

    Dynamic Table Creation, colspan issue.

    Hello,
    I've done some searching around the post, and I have found quite a bit of information related to the setAttribute and it's related uses. My problem lies in the usage of colspanning in dynamic table creation.

    Code Snippet
    [CODE=javascript]<SCRIPT LANGUAGE="JavaS cript">
    function morecase(id){
    var tbody = document.getEle mentById(id).ge tElementsByTagN ame("TBODY")[0];
    var row1=document.c reateElement('T R');
    var row1td1=documen t.createElement ('TD');
    row1td1.appendC hild(document.c reateTextNode(' Incident: '));
    var row1td2=documen t.createElement ('TD');
    row1td2.appendC hild(document.c reateElement('I NPUT'));
    row1td2.setAttr ibute('TYPE','t ext','NAME','in cident');
    var row2=document.c reateElement('T R');
    var row2td1=documen t.createElement ('TD');
    row2td1.appendC hild(document.c reateTextNode(' Blah blah blah blah blah blah blah'));
    row2td1.setAttr ibute('colspan' ,'2');
    row1.appendChil d(row1td1);
    row1.appendChil d(row1td2);
    row2.appendChil d(row2td1);
    tbody.appendChi ld(row1);
    tbody.appendChi ld(row2);
    }
    </script>
    [/CODE]
    Everything works, but the COLSPAN does not process.
    I can pass other commands to the TD (width, bgcolor, etc.) and they work fine, COLSPAN is just my headache.

    Any help would be greatly appreciated!

    William

    POST NUMBER 1 Woo! :rolleyes:
    Last edited by acoder; Feb 29 '08, 11:07 AM. Reason: Added code tags
  • william_dean
    New Member
    • May 2006
    • 2

    #2
    Recoded, now I get an empty error, object expected 0,0

    NM, I fixed it :-)
    Last edited by william_dean; May 14 '06, 09:50 PM. Reason: cuz it doesn't matter

    Comment

    • gupyuson
      New Member
      • Sep 2006
      • 1

      #3
      How did you fix it?

      Originally posted by william_dean
      Hello,
      I've done some searching around the post, and I have found quite a bit of information related to the setAttribute and it's related uses. My problem lies in the usage of colspanning in dynamic table creation.

      Code Snippet
      <SCRIPT LANGUAGE="JavaS cript">
      function morecase(id){
      var tbody = document.getEle mentById(id).ge tElementsByTagN ame("TBODY")[0];
      var row1=document.c reateElement('T R');
      var row1td1=documen t.createElement ('TD');
      row1td1.appendC hild(document.c reateTextNode(' Incident: '));
      var row1td2=documen t.createElement ('TD');
      row1td2.appendC hild(document.c reateElement('I NPUT'));
      row1td2.setAttr ibute('TYPE','t ext','NAME','in cident');
      var row2=document.c reateElement('T R');
      var row2td1=documen t.createElement ('TD');
      row2td1.appendC hild(document.c reateTextNode(' Blah blah blah blah blah blah blah'));
      row2td1.setAttr ibute('colspan' ,'2');
      row1.appendChil d(row1td1);
      row1.appendChil d(row1td2);
      row2.appendChil d(row2td1);
      tbody.appendChi ld(row1);
      tbody.appendChi ld(row2);
      }
      </script>

      Everything works, but the COLSPAN does not process.
      I can pass other commands to the TD (width, bgcolor, etc.) and they work fine, COLSPAN is just my headache.

      Any help would be greatly appreciated!

      William

      POST NUMBER 1 Woo! :rolleyes:

      Comment

      • papppp
        New Member
        • Oct 2006
        • 1

        #4
        Not very polite to say you fixed it and not to explain HOW, don't you think?

        Anyway, colspan is actually spelled colSpan! It is a "casing" problem.

        Comment

        • kiuziu
          New Member
          • Dec 2006
          • 1

          #5
          [CODE=javascript]tr1 = document.create Element('tr');
          tbody1.appendCh ild(tr1);
          td1 = document.create Elemen("td");
          tr1.appendChild (td1);
          td1.setAttribut e("colSpan",2 );
          [/CODE]


          //ok
          Last edited by acoder; Feb 29 '08, 11:08 AM. Reason: Added code tags

          Comment

          • ionutkit
            New Member
            • Jan 2007
            • 1

            #6
            Another solution:

            var td = document.create Element('td');
            td.colSpan = 5; // for example

            Comment

            • itb564
              New Member
              • Feb 2008
              • 1

              #7
              It is really working, but it is not becoming a static table row.
              How should i make it as a static one?

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                By static, do you mean fixed width? Post your code.

                Comment

                • gestrada
                  New Member
                  • Oct 2008
                  • 1

                  #9
                  Originally posted by ionutkit
                  Another solution:

                  var td = document.create Element('td');
                  td.colSpan = 5; // for example

                  colSpan .. eso ers muchas gracias !!!!

                  Comment

                  Working...