aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes adding and deleting a row in html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "adding and deleting a row in html" Watch "adding and deleting a row in html" New topic
Author

adding and deleting a row in html

rammie singh
Ranch Hand

Joined: Mar 26, 2009
Posts: 116
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

Joined: May 04, 2009
Posts: 3
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

Joined: Oct 03, 2007
Posts: 50
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

Joined: Mar 26, 2009
Posts: 116
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: adding and deleting a row in html