canceling onclick event for some cells in the table

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
toraj58
Forum Newbie
Posts: 12
Joined: Sun Jun 15, 2008 12:40 am

canceling onclick event for some cells in the table

Post 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...
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: canceling onclick event for some cells in the table

Post 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;
}
 
toraj58
Forum Newbie
Posts: 12
Joined: Sun Jun 15, 2008 12:40 am

Re: canceling onclick event for some cells in the table

Post by toraj58 »

i want stop the event from bubbling...also where in the code should i call the function that you have proposed?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: canceling onclick event for some cells in the table

Post 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.
toraj58
Forum Newbie
Posts: 12
Joined: Sun Jun 15, 2008 12:40 am

Re: canceling onclick event for some cells in the table

Post by toraj58 »

i think Kieran Huggins's answer is near to what i want to do but somewhat i need more explanation.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: canceling onclick event for some cells in the table

Post by kaszu »

Check http://www.quirksmode.org/js/introevents.html ,good explanation for it.
Post Reply