Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9156425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:46:27+00:00 2026-06-17T12:46:27+00:00

I have Javascript like the following: function addRow(table1) { var table = document.getElementById(table1); var

  • 0

I have Javascript like the following:

function addRow(table1) {

            var table = document.getElementById(table1);

            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);

            var colCount = table.rows[0].cells.length;

            for(var i=0; i<colCount; i++) {

                var newcell = row.insertCell(i);

                newcell.innerHTML = table.rows[0].cells[i].innerHTML;
                //alert(newcell.childNodes);
                switch(newcell.childNodes[0].type) {
                    case "text":
                            newcell.childNodes[0].value = "";
                            break;
                }
            }
        }

And HTML like the following:

<input type="button" value="Insert row" onclick="addRow('table1')" />
<table id="table1" border=1>
    <tr>
        <td rowspan=2><input type="text" name="txt1"></td>
        <td><input type="text" name="txt2"></td>
    </tr>
    <tr>
        <td><input type="text" name="txt3"></td>
    </tr>
</table>

I have a row with rowspan=2, and two rows with no rowspan. How do I write the following line so that once the user clicks the Insert Row button, three textboxes will be added into the new row?

newcell.innerHTML = table.rows[0].cells.innerHTML;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:46:28+00:00Added an answer on June 17, 2026 at 12:46 pm

    Note that in your code you have:

    > newcell.innerHTML = table.rows[0].cells.innerHTML;
    

    I think you mean:

    newcell.innerHTML = table.rows[0].cells[i].innerHTML;
    

    But anyway, have you considered using a cloned row instead? e.g. something like the following (untested):

    function addRow(tableID) {
      var table = document.getElementById(tableID);
      var row = table.rows[0].cloneNode(true);
      var inputs = row.getElementsByTagName('input');
      var i = inputs.length;
    
      while (i--) {
    
        if (inputs[i].type = 'text') {
          inputs[i].vaule = '';
    
          // Might want to change other properties too
        }
      }
      table.tBodies[0].appendChild(row);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have some Javascript code like the following... (function(){ var a = 'valueA';
I have used Javascript onlaod like this: function check() { var pic = new
Let's say I have some simple Javascript like: <script> var hello = function(){ alert(Hello
let's say I have a simple javascript like so: $(document).ready(function(){ if(login == 1) {
I have initialized my form submission like following: $(document).ready(function() { $(#my_form).submit(function(e) { ... ...
Please help me out on this. I have Javascript like the following: function calc()
Let's say I have the following javascript: (function($) { $.getJSON(url, function(data) { $.each(data.rows, function(index,
i have JavaScript components, that has following architecture: var MyComponent = function(params) { setup(params);
I have a JavaScript object that looks like the following: venue = function(map, dataSet)
I have a bunch of Javascript functions that look like the following: function generateBusinessImage

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.