adding multiple rows to a table at one go.

Discussion in 'Javascript' started by Amy, Sep 5, 2006.

  1. Amy

    Amy Guest

    Is it possible to do so?
     
    Amy, Sep 5, 2006
    #1
    1. Advertising

  2. Amy wrote:
    > Is it possible to do so?


    Do what?

    Richard.
     
    Richard Cornford, Sep 5, 2006
    #2
    1. Advertising

  3. Amy

    Jim Guest

    Amy wrote:
    > Is it possible to do so?
    >

    Simple answer, yet.

    Really horrible script demonstrating a way to add 2 rows:

    <html>

    <body>





    <script type="text/javascript">

    function addRow(id){
    var table = document.getElementById(id);
    var rowToClone = table.rows[0];
    var oRow = rowToClone.cloneNode(true);
    var input = oRow.getElementsByTagName('input')[0];
    input.name = 'input' + table.rows.length;
    input.value = '';
    rowToClone.parentNode.appendChild(oRow);
    }

    function add2Row(id){
    var table = document.getElementById(id);
    var rowToClone = table.rows[0];
    var oRow = rowToClone.cloneNode(true);
    var input = oRow.getElementsByTagName('input')[0];
    for(var i=0;i<2;i++) {
    input.name = 'input' + table.rows.length;
    input.value = '';
    rowToClone.parentNode.appendChild(oRow);
    }
    }

    </script>

    <button onclick="addRow('tableA')">Add row</button><br>
    <button onclick="add2Row('tableA')">Add 2 rows</button>
    <form action="">
    <table id="tableA">
    <tr>
    <td><input name="input0" onclick="this.value=this.name"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
     
    Jim, Sep 6, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Meade
    Replies:
    4
    Views:
    7,318
    Rob Meade
    Nov 25, 2003
  2. lucky
    Replies:
    0
    Views:
    515
    lucky
    Jan 12, 2005
  3. Subba Rao via DotNetMonster.com

    script for moving rows up and down and traverse thru rows of HTML table

    Subba Rao via DotNetMonster.com, Mar 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    8,238
    Subba Rao via DotNetMonster.com
    Mar 19, 2005
  4. Rio
    Replies:
    4
    Views:
    1,199
  5. PT
    Replies:
    1
    Views:
    396
    Ken Schaefer
    Oct 7, 2004
Loading...

Share This Page