I've series of checkbox, for which I've written jquery script on click. When user clicks on checkbox it opens another series of checkbox and it goes on. Now my problem is when users checks few of those checkbox, and moves to next page and for some reason he/she comes back to checkbox page. Then I should have all the boxes which he/she has checked to open up. I've written a check box test when dom loads
$(document).ready(function(){
if($('.main').is(':checked')){
$(this).trigger('click');
}else{
//do nothing
}
$('.main').click(function(){
if($('.main').is(':checked')){
var val = $(this).attr('alt');
$('#'+val).show();
}else{
var val = $(this).attr('alt');
$('#'+val).hide();
}
});
});
As you see above. Main is the checkbox class. On click of that, am opening another series of checkbox. Now I want this to done automatically for their checked boxes when they visit the page again
use session or cookie to save .main class checkbox values and checked those accordingly when you come back and then use the following code:
<script type="text/javascript">
$(document).ready(function(){
$('.main').each(function(){
if($(this).is(':checked')){
var val = $(this).attr('alt');
$('#'+val).show();
}else{
var val = $(this).attr('alt');
$('#'+val).hide();
}
});
if($('.main').is(':checked')){
$(this).trigger('click');
}else{
//do nothing
}
$('.main').click(function(){
if($('.main').is(':checked')){
var val = $(this).attr('alt');
$('#'+val).show();
}else{
var val = $(this).attr('alt');
$('#'+val).hide();
}
});
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With