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

  • Home
  • SEARCH
  • 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 8422139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:21:24+00:00 2026-06-10T03:21:24+00:00

This is my javascript to copy row and remove row function cloneRow() { var

  • 0

This is my javascript to copy row and remove row

function cloneRow()
 {
         var row = document.getElementById("r1"); 
         var table = document.getElementById("t1"); 
         var clone = row.cloneNode(true); 
         clone.id = "newID";
         table.appendChild(clone); 
 }
 function removeRowFromTable()
 {
 var tbl = document.getElementById('div1');
 var lastRow = tbl.rows.length;
 if (lastRow > 1) tbl.deleteRow(lastRow - 1);
 }

and this is my table:

 <table id="div1" style="display:none">
    <tbody id="t1">
    <tr id="r1"><td>
<form:input path="hostname" value="hostname" onfocus="if(this.value == 'hostname'){this.value =''}" onblur="if(this.value == ''){this.value ='hostname'}" size="30" maxlength="30"/>
<form:input path="directory" value="directory" onfocus="if(this.value == 'directory'){this.value =''}" onblur="if(this.value == ''){this.value ='directory'}" size="15" maxlength="15"/>
<form:input path="username" value="username" onfocus="if(this.value == 'username'){this.value =''}" onblur="if(this.value == ''){this.value ='username'}" size="15" maxlength="15"/>
<form:input path="password" value="password" onfocus="if(this.value == 'password'){this.value =''}" onblur="if(this.value == ''){this.value ='password'}" size="15" maxlength="15"/></td></tr>
    </tbody>
<input type="button" onclick="cloneRow()" value="+" />
<input type="button" onclick="removeRowFromTable();" value="-" />
    </table>

code is working to add or remove the rows dynamically..but, how can I know they are creating with unique ids..i need to save the values to database later on

  • 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-10T03:21:26+00:00Added an answer on June 10, 2026 at 3:21 am

    Use a closure with a local variable:

    var cloneRow = (function()
    {
        var id_num = 0;
    
        return function ()
        {
            var row = document.getElementById("r1"); 
            var table = document.getElementById("t1"); 
            var clone = row.cloneNode(true); 
    
            clone.id = "newID" + id_num++;
            table.appendChild(clone); 
        };
    }());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With this javascript I'm printing list of records: <script type=text/javascript> $(document).ready(function(){ function hide(){ $('#friend_list').fadeIn(100);
This Javascript code is using the 'this' keyword inside a nested function (which is
This javascript function takes JSON and formats it to XML. The data is a
I have this Javascript function that sends username and password to php file through
I have this Javascript: <script language=javascript type=text/javascript> $().ready(function() { $('#ex2').jqm({ajax: 'view.php?id=<?=$objResult[id];?>', trigger: 'a.ex2trigger'}); });
I have the following Javascript to copy the user's textarea input in this iPhone
I use this Javascript code to mark threads as favourite: function fave(tid){ xmlhttp =
I'm using a javascript function on this site to have a slideshow of images.
I need some javascript (not JQuery etc) codes to copy a clone node and
What I am trying to do is build a clone() function for Javascript objects.

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.