• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding and deleting a row in html

 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have certaing heading in a table and above that table there is link .

My Requirement is : if a click on the link a new row should be craeted automatically with all the input box and other options in the row.

and if the particular row is checked ,the row is deleted.

can any body plase help me how to implement this....or any mataerial where i can get some help.

Thanks
Regards
 
Rocky Pareek
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rammie singh wrote:i have certaing heading in a table and above that table there is link .

My Requirement is : if a click on the link a new row should be craeted automatically with all the input box and other options in the row.

and if the particular row is checked ,the row is deleted.

can any body plase help me how to implement this....or any mataerial where i can get some help.

Thanks
Regards


to delete rows
the script is as:

function deleteRows(rowObjArray)
{
if (hasLoaded) {
for (var i=0; i<rowObjArray.length; i++) {
var rIndex = rowObjArray[i].sectionRowIndex;
rowObjArray[i].parentNode.deleteRow(rIndex);
}
}
}


call in html page

<input type="button" value="Delete [D]" onclick="deleteChecked();" />
 
Romit Bose
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rammie,
i had a requirement like this in one of my projects.
i can suggest two methods:
1) get a reference to the last row and use cloneNode.
something like : pass the ref to the last node from where you are calling the method
function addRow(key){

document.getElementById("YourTable").appendChild(key.cloneNode(true));

}



2) Its pretty easy - first you add the row to the table and then create the cells and add them to your newly created row. refer to the following code and tell me if this works for you.
 
rammie singh
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried somthing like this.....




but this code has some problem.
first : it has serial number for each rows. but when we delete the row and again add a row it starts from the same previous row serial number .foe example

i have added 1 ,2 , 3, 4 rows.
now i delete 3 rd row then next row would be again 4th. and hence index no 4 is repeated...and so on.

can any one please tell me where the problem is.

second also i don't require this index in my code. what can i do to remove this index.

Thanks
Regards
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are looking at the number of rows. The HTML has no clue you deleted a row. If you want the number to increase, you need to keep a counter and not read the length.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic