New to javascript. I'm trying to access a variable from within a function to trigger an ajax call. Any help greatly appreciated.
document.onkeydown = logKey;
i = 0;
function logKey(e) {
var keys = i += 1;
};
console.log(keys);
Uncaught ReferenceError: keys is not defined
It was a scope issue as pointed out by @sanketd617. I used the following from @Arun P Jonny
$(document).ready(function () {
var idleTime = 0;
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 60000);
//Zero the idle timer on keypress.
$(this).on('keypress', function (e) {
console.log('reset: ', e.type)
idleTime = 0;
});
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > 1) {
console.log(idleTime)
}
}
});