//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

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.

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.

Thanks for the reply.

But this is not working.
shows current isundefined

Please post your code.

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);
  }

That is not the code I gave you.

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);
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.