I'm trying to store the value of an input (in an array) each time it is updated. I have multiple inputs with the structure:
<input class="inf" key="213" type="CUSTOM" value="val">
Then I had this working function:
$('.inf').on('keyup', function () {
clearTimeout(temp2);
temp2= setTimeout(updateValues.call(this), doneTypingInterval);
});
But the setTimeout doesn't work, so I used this solution and changed it to:
temp2= setTimeout(function () {updateValues.call(this);}, doneTypingInterval);
Now, setTimeout
is working but, when updateValues
is reached, all 3 variables are "undefined".
updateValues function:
var updateValues= function(){
key=$(this).attr("key");
type=$(this).attr("type");
value=this.value;
upd={
"name" : '"'+key+'"',
"type" : '"'+type+'"',
"value" : '"'+value+'"'
};
nw = nw.concat(upd);
console.log(nw);
};
The problem is that the this
object in updateValues
is what I passed with the call
. Any suggestions?