This is my current solution:
html
<input type="checkbox" value="1" onclick="return do_stuff();" />
<input type="checkbox" value="1" onclick="return do_stuff2();" />
javscript:
function do_stuff() {
return false;
}
function do_stuff2() {
return true;
}
http://jsfiddle.net/NXKMH/12/
I would like to avoid needing the "return" in the onclick call (ex. onclick="do_this();"
instead of onclick="return do_this();"
). I thought about using the preventDefault() function that jquery provides, but cant seem to get that working. Also, I dont want to bind "click" event if possible. I prefer using the "onclick". (easier to work with ajax loaded content)
Thoughts?
Have you tried calling the event.stopPropagation() method inside do_stuff() ... you'll need to pass in the event of course.
onclick = 'do_stuff(event)'
function do_stuff(ev) {
if(ev.stopPropagation) {
// for proper browsers ...
ev.stopPropagation();
} else {
// internet exploder uses cancelBubble ...
window.event.cancelBubble = true;
}
// --- do some more stuff ---//
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With