I'm using the technique outlined here to do a partial page refresh periodically. What I was wondering is if it is possible to do a partial page refresh but not refresh some elements within the div that is being refreshed? I have some checkboxes that lose the checked state each time the page refreshes. I would like to not refresh these checkboxes.
+2
A:
If each checkbox has an id, you could backup the state before the reload, and restore it afterwards. Something like:
var checkboxstate ;
function saveCheckboxState() {
checkboxstate = new Array() ;
$('input:checkbox:checked').each(function() {
checkboxstate[checkboxstate.length] = this.id ;
}) ;
}
function restoreCheckboxState() {
for(var i=0;i < checkboxstate.length;i++) {
$('input:checkbox#' + checkboxstate[i]).each(function() {
this.checked = true ;
}) ;
}
}
Gus
2010-09-30 23:41:43
Just wondering, why do you write a space before the trailing semicolon? BTW, `[]` is shorter than `new Array()`. And you can also use [`Array.push`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push), but this will work, too.
Marcel Korpel
2010-09-30 23:44:06
I started doing it when I found that the editor that I was using would select the semicolon with the last item in the line when I double-clicked it. I think I was doing lots of css attribute changes at the time and being able to double click to select rather than dragging really saved some time. Since then, it's sort of become a habit.
Gus
2010-09-30 23:53:06
Awesome, that did it. Thanks!
Prabhu
2010-09-30 23:54:57