I am encountering an issue where a method is throwing an undefined variable error, despite verifying the variable's state before calling it.
// This function sets focus and text-select on the element passed in.
idNav.prototype.setFocusFromVar = function(r) {
document.activeInputArea = r; // tracking focus with this variable
r.focus(); // error occurs here (line 274 of idNav.js)
r.select();
}
The error specifically arises at the line where r.focus is called.
Every time I invoke this method, I follow a similar pattern as shown below with a local variable 'r' in the caller function.
if (!r)
return;
this.setFocusFromVar(r);
Yet, the error persists. When 'r' is not null or undefined, it represents an input element within a table on my webpage.
I consistently encounter the "r is undefined" error at line 274 of idNav.js, which is the 'r.focus' line. All method calls are made from within the same JavaScript file.
What could possibly be missing?
This error only seems to happen sporadically in Firefox; I have not tested it in IE.
EDTA: 'r' did appear to be undefined and the error stack trace reads:
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 reviewed, and it seemed to be functioning without any issues. I will re-examine it to double-check:
This method is responsible for managing key events like down-arrow and enter keys for navigating through the input elements within my table.