I am using a toggle link to show and hide some page content on a search page. The toggle is set to hide
on page load.
Function works great but I will need to remember the toggle state on form submit so that if the user decides to edit the initial search the state is remembered.
Here is the working function:
$(document).ready(function(){
$(".slidingDiv").hide();
$(".show_hide_search").show();
$('.show_hide_toggle').on('click', function(e){
e.preventDefault();
var self = this,
sliding = $(this).closest('div').next('.slidingDiv').slideToggle(function(){
$($(self).children()[0]).text(function(_,txt) {
return txt == "–" ? "+" : "–";
});
});
});
});
And the HTML:
<div class="show_hide_toggle">
<a href="#" class="show_hide_search" id="plus">+</a>
<div class="show_hide_search2">More</div>
</div>
<div class="slidingDiv" style="display: block;">
<h2>Content One</h2>
</div>
This is how I remember the session for the form elements if it helps:
<?php echo ($_SESSION['save_srch']['name1'] == 'name')?'selected="selected"':'';?>
Here is a JSFiddle: http://jsfiddle.net/Bradg/eBfxB/11/