0

//This is my html code

<INPUT TYPE=\"Button\" CLASS=\"Button\" onClick=\"delRow()\" VALUE=\"Delete Row\">

//this is javascript function for deleting a row
function delRow()
  {
    var current = window.event.srcElement;
    
    //here we will delete the line
    while ( (current = current.parentElement)  && current.tagName !="TR");
         current.parentElement.removeChild(current);
  }

Thanks,
Sura

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by fxm
0

This thread was over three years old before you resurrected it.
You may get more attention to your question if you start a new thread.

0

To handle events in a cross-browser fashion you need something like this

document.onclick = delRow;

function delRow(e)  {

    e = e || event;
    var current = e.srcElement || e.target;

Warning: you will now get all click events, so you must return from this function without doing anything whenever the calling element is not one that you were expecting.

0

Thanks for the reply.

But this is not working.
shows current isundefined

0

Hi,
Thanks for the reply. This is my code. This code is not working in

//html
<table id='tblPets' border='0' cellspacing='3' >

    <tr>
    <td align='center'>
<select name='icdcode[]' id='icdcode[]' >
</select></td><td><span style='cursor:pointer;cursor:hand;' onclick=addRow(\"tblPets\")>Add</span></td></tr></table>


//javascript code
function delRow()
  {
    var current = window.event.srcElement;
     while ( (current = current.parentElement)  && current.tagName !="TR");
         current.parentElement.removeChild(current);
  }

Edited by Reverend Jim: Fixed formatting

0

I added your code like this. It gives current is not defined in FF.


<table id='tblPets' border='0' cellspacing='3' >

<tr>
<td align='center'>
<select name='icdcode[]' id='icdcode[]' >
</select></td><td><span style='cursor:pointer;cursor:hand;' onclick=addRow(this)>Add</span></td></tr></table>

//javascript code
function delRow(e)
{
//var current = window.event.srcElement;
e = e || event;
var current = e.srcElement || e.target;
while ( (current = current.parentElement) && current.tagName !="TR");
current.parentElement.removeChild(current);
}

0

You omitted the mandatory document.onclick assignment - line 1 in my code snippet.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.