I have a timer function I got off this site and have tried to modify it a bit to suit my needs. For the most part it works as I’d like but I’m not able to pass a parameter to the JavaScript function.
I want to use a select to change the id value, then pass that value into the JQuery load function. Can someone please show me how to do this?
It may be worth mentioning that when the the timer refreshes, the select value needs to “stick”, it can’t reset.
Here is what I have so far:
function RecurringTimer(callback, delay) {
var timerId, start, remaining = delay;
this.pause = function() {
window.clearTimeout(timerId);
remaining -= new Date() - start;
};
var resume = function() {
start = new Date();
timerId = window.setTimeout(function() {
remaining = delay;
resume();
callback();
},remaining);
};
this.resume = resume;
this.resume();
}
var timer = new RecurringTimer(function() {
$('#id').load('load.asp?id=1'); // The "id" should be "newVal" from JQuery below.
}, 5000);
$(document).ready(function(){
$('#appList').live('change',function(){
var select = $(this);
var newVal = select.val();
if(newVal != ''){
// This is where the var newVal needs to be passed into the JavaScript.
}
});
});
Well, you could do:
And use
window.newValwhere needed: