[SOLVED] preserve the state of checkboxes after an AJAX call

This is a discussion on "[SOLVED] preserve the state of checkboxes after an AJAX call" within the JavaScript Forum section. This forum, and the thread "[SOLVED] preserve the state of checkboxes after an AJAX call are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 7th, 2007, 14:34
Junior Member
Join Date: Oct 2007
Location: Holland
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] preserve the state of checkboxes after an AJAX call

Hi all

Upon a checkbox click I'm calling a JavaScript function, which asynchronously requests information from the server. The server returns a .jsp fragment, which is plugged in the place of the checkbox region.
Therefore, the marked checkboxes become blank after the servlet responds. Any ideas how I can preserve their state.



Thanks,
Pesho
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 7th, 2007, 14:46
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: preserve the state of checkboxes after an AJAX call

You mean the checkbox is replaced with the new code? Or why is it resetted?

Maybe just save the checked stat of the checkbox, and reset it after the AJAX call?!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 7th, 2007, 14:51
Junior Member
Join Date: Oct 2007
Location: Holland
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Re: preserve the state of checkboxes after an AJAX call

yes, it is replaced with the new code. How can I save the stat and reset it afterwards, could you be more precise?

thank you!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 7th, 2007, 15:17
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: preserve the state of checkboxes after an AJAX call

Just save the check states to a variable before you do the AJAX call, and restore it afterwards
Code: Select all
var checkstate = new Array; // define global checkstate
...

// Save State
var checkboxes = document.formname.checkboxesname;
for(i=0;i<checkboxes.length;i++)
{
  checkstate[i] = checkboxes[i].checked;
}
...
AJAX
...
// Restore
var checkboxes = document.formname.checkboxesname;
for(i=0;i<checkboxes.length;i++)
{
  checkboxes[i].checked = checkstate[i];
}
You could even cycle through all checkboxes of the page by getting them with document.getElementsByName('input') and checking if their "type == 'checkbox'".
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 7th, 2007, 16:35
Junior Member
Join Date: Oct 2007
Location: Holland
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Re: preserve the state of checkboxes after an AJAX call

great !

thank you for the elegant solution

cheers,
Pesho
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in IE after asynchronous (AJAX) call pesho318i Web Page Design 3 Mar 21st, 2008 15:17
Call PHP Web Service With Ajax 2mk PHP Forum 5 Feb 9th, 2008 22:02
preserve the back button action when doing AJAX calls pesho318i JavaScript Forum 2 Nov 28th, 2007 12:37
[SOLVED] AJAX call to a servlet pesho318i JavaScript Forum 9 Oct 28th, 2007 12:40
AJAX call function melvinoyh JavaScript Forum 2 May 31st, 2006 01:02


All times are GMT. The time now is 01:51.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42