I have this script:
function postBackByObject(e) {
var o = window.event.srcElement || e.target;
if (o.tagName == "INPUT" && o.type == "checkbox") {
__doPostBack("", "");
}
}
I use this script with onclick="postBackByObject();"
.
but in Firefox 21 I get this error:
TypeError: window.event is undefined
what is my wrong?
You are attaching events inline onclick="postBackByObject();"
Try passing this
(the event target) to onclick="postBackByObject(this);"
Modify your function to handle this change:
function postBackByObject(e) {
if (e.tagName == "INPUT" && e.type == "checkbox") {
__doPostBack("", "");
}
}
A better alternative will be to attach events using addEventListener
If your markup looks like:
<div id="TvCategories" onclick="postBackByObject(this);" />
then
document.getElementById('TvCategories').addEventListener('click', postBackByObject);
Your postBackByObject
function remains unchanged when using this approach.
That's because it is. window.event
is for older versions of IE.
The typical way to do this is:
function postBackByObject(e) {
e = e || window.event;
var o = e.srcElement || e.target;
// ...
}
Pass the event on the onClick
event like this:
onclick="myCustomFunction(event);"
It does work and you can access the event object!
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