Skip to main content

Dynamically Add/Remove Rows in HTML Table Using Javascript

Following code snippet will show how to dynamically add/remove rows in Table using simple HTML and Javascript :

Source Code :
 HTML Table :  
 <table cellspacing=0 cellpadding=0 border=0 border-spacing=10px id="attributes_configuration_table">  
       <tr id="row_1">          
         <input type="text" name="attribute_name_1" id="attribute_name_1" style="margin-right:10px" autocomplete="off">                  
         <input type="text" name="attribute_value_1" id="attribute_value_1" style="margin-right:10px" autocomplete="off">          
       <td><input class="new_button" id="+" name="+" onclick="addTableRow('attributes_configuration_table')" type="button" value="+">  

JavaScript :
 var counter = 1;  
 function addTableRow(TableId) {  
   var table = document.getElementById(TableId);  
   var rowCount = table.rows.length;  
   var row = table.insertRow(rowCount); = 'row_' + counter;  
   var cell1 = row.insertCell(0);  
   var element1 = document.createElement("input");  
   element1.type = "text";  
   element1.autocomplete = "off";"attribute_name_" + counter;  
   var cell2 = row.insertCell(1);  
   var element2 = document.createElement("input");  
   element2.type = "text";  
   element2.autocomplete = "off";"attribute_value_" + counter;  
   var cell3 = row.insertCell(2);  
   var newButton    = document.createElement("input");  
   newButton.className = "new_button";  
   newButton.type   = "button";  
   newButton.value   = '-';  
   newButton.onclick  = removeRow;  
 function removeRow (id) {  
   var rowNode = this.parentNode.parentNode;  
   // Delete this node  

Live Demo


Popular posts from this blog

Hello World

I had heard about blogs few years back. Since then I wanted to write my blog. But, for some reasons like, what to write, how to write etc, always stopped me. Finalizing an address for the blog is most depressing thing. Address of your choice will be unavailable and to think of a name, which would be available will take a lot of time. " Sorry, this blog address is not available " will vanish your enthusiasm/excitement for blogging, unless you come up with a really unique and out-of-box kind of word/words. BTW, my blog name is not so out-of-box, but it's in Hindi (my mother-toung). This blog-name thing is one of the significant reason, I am coming up with my blog a bit late. Logged in to blogger so many times earlier, but I was not getting a name which I like. But, this time I was determined to start my blog and So friends, this is the start of  "". Edit: Now, I have a custom domain "" for my blog. Thank

Sakleshpur - The Green Route Railway Trek, Waterfalls, Jungle Adventures and Much More

The breathtaking images of picturesque railway route from Sakleshpur to Kukke Subramanya captivated us to go for this trek. We had been planning to do "The Green Route trek" - that's what it is called, from last few months and then finally the day has come and we started for our journey to Sakleshpur - also referred as "Poor Man's Ooty". We read some news about the ban on trekking in western ghats. But we were not sure if it is really banned. Before the conversion of the railway line from meter gauge to broad gauge along the Sakleshpur railway line in Karnataka’s Hassan district, it was one of the most sought-after trek routes. 1, 2, 3 - Smile 1, 2, 3 - Smile We started our journey from Bangalore on Friday evening, had dinner enroute in a dhaba near Hassan and reached Sakleshpur at around the Midnight, Checked into Hotel. Next morning, We talked to some local people and We came to know "The Green Route" Trek is banned for sure. Bu

Mangalyaan is launched successfully - What Next ?

At 2:38 PM, 5 November - Two days post Diwali, ISRO successfully lauched a rocket " Majestic PSLV C25 " towards planet Mars as if they were celebrating Diwali, after spending numerous sleepless nights in their endeavour to make the launch successful, at Satish Dhawan Space Centre, Sriharikota . Mangalyaan blasts off from its launchpad India is the first Asian country and the fourth in the world to undertake a mission to the red planet. That's the reason, " A Billion Hopes " were riding with the Mangalyaan launch. ISRO made us feel proud and we can held our head high for the success. Clouds kissing the ground - Seconds after the launch About 45 minutes after the launch, Mars Orbitor Mission (MOM) Satelite, Mangalyaan , separated from its launch rocket and launch rocket has placed the Orbiter very precisely in an elliptical orbit around Earth, which makes the First Stage successful. Now, Mangalyaan, is expected to go around the Earth for about a mo