I have a problem where a method is getting an undefined variable error, even though I check for the variable being undefined before calling.
// Sets focus and text-select to the passed in element.
idNav.prototype.setFocusFromVar = function(r) {
document.activeInputArea = r; // my variable for tracking focus
r.focus(); // error happens here (line 274 of idNav.js)
r.select();
}
The error happens at the r.focus line.
In both places where I call the method, I use a pattern similar to the following with a local variable r in the caller.
if (!r)
return;
this.setFocusFromVar(r);
and yet the error persists. When r is not null or undefined, it is an input element in a table on my webpage.
I continue to get r is undefined on line 274 of idNav.js, which is the r.focus line. All of the callers of the method are in the same js file as well.
What am I missing?
This error is occurring intermittently in Firefox, I haven't tested this specific error in IE.
EDTA: r did show up as an undefined and the stack trace of the error shows:
setFocusFromVar()(undefined)IDNav.js (line 275)
dhandler(Object originalEvent=Event keydown type=keydown)IDNav.js (line 100)
newTrigger()(Object originalEvent=Event keydown type=keydown)jquery.hotkeys.js (line 1)
F()()jquery.js (line 19)
F()(Object originalEvent=Event keydown type=keydown)jquery.js (line 19)
F()()jquery.js (line 19)
[Break on this error] r.focus();
dhandler is one of the methods I checked out and seemed to be good (no problems). I will take another look at that to be sure though:
It is used for handling the down-arrow and enter keys for navigation through my table of input elements.