Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Specific Row Based on ID

Status
Not open for further replies.

Signit

MIS
Oct 17, 2003
114
US
I've written a piece function that is supposed to delete a particular row in table based on the id of that row. For some reason beyond my comprehension the below code deletes multiple rows from my table but not the one I am interested in deleting. Why is this? What am I missing?

Code:
function deleteRows(obj)
{
  for (var i = 0; i <= obj.rows.length; i++)
  {
    if (obj.rows[i].getAttribute("id") == "acc_date");
      obj.deleteRow(i);
  }
}
 
Okay, so moments after I posted this I found my problem and I am blushing. Though it does lead me to another question. Why does the below code throw an "Expected Identifier" error?

Code:
deleteRows(document.getElementById("entire_page"), "acc_date");

function deleteRows(obj)
{
  for (var i = 0; i < obj.rows.length; i++)
  {
    if (obj.rows[i].getAttribute("id") == "doe_acc_date")
      obj.deleteRow(i);
  }
}
 
My copy and paste skills leave something to be desired today, please use the below code:

Code:
function deleteRows(obj, var rowToDelete)
{
  for (var i = 0; i < obj.rows.length; i++)
  {
    if (obj.rows[i].getAttribute("id") == rowToDelete)
      obj.deleteRow(i);
  }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top