Page 1 of 1

canceling onclick event for some cells in the table

Posted: Mon Jun 16, 2008 5:51 am
by toraj58
i have wrote an onclick event for the rows of the table (<tr> tag) but i want to disable the onclick for two columns (<td> tag). what should i do?
by defualt when i enable onclick for a row it will works for all the column in the row.
my row has 12 columns and i don't need onlick for the last twos. one solution is that i repeat the same code for 10 columns instead of the row but it is not a good approach. i think there should be some event arguments like c++ and C# that can reveal which cell has been clicked and if it was a special one then the code can cancel onclick event. i appriciate any help...

Re: canceling onclick event for some cells in the table

Posted: Mon Jun 16, 2008 5:56 am
by Kieran Huggins
you want to stop the event from "bubbling" or "propagating", depending on who makes the browser.

here's a little cross-browser script (from PPK) that should help:

Code: Select all

function stopProp (e) {
    var evt = e || window.event;
    if (evt.stopPropagation)
        evt.stopPropagation();
    evt.cancelBubble = true;
}
 

Re: canceling onclick event for some cells in the table

Posted: Mon Jun 16, 2008 6:33 am
by toraj58
i want stop the event from bubbling...also where in the code should i call the function that you have proposed?

Re: canceling onclick event for some cells in the table

Posted: Mon Jun 16, 2008 4:28 pm
by Ambush Commander
The event handler for the td cells.

Actually, repeating things for the 10 columns isn't too far-fetched if you use JavaScript to set the event handlers.

Re: canceling onclick event for some cells in the table

Posted: Tue Jun 17, 2008 12:06 am
by toraj58
i think Kieran Huggins's answer is near to what i want to do but somewhat i need more explanation.

Re: canceling onclick event for some cells in the table

Posted: Tue Jun 17, 2008 2:52 am
by kaszu
Check http://www.quirksmode.org/js/introevents.html ,good explanation for it.