There appears to be an issue with my attempt to implement check boxes (or radio buttons) and displaying hidden content.
Html
<input type="checkbox" id="carousel" class="carouselGlobal" name="aisis_options[carousel_global]" value="carousel_global">
Simple check box. Now let's utilize some jquery to show a hidden section, with the div class of .sectionCarousel
jQuery
$('.carouselGlobal').click(function(){
if ($(this).attr("id") == "carousel"){
$('.sectionCarousel').show();
} else {
$('.sectionCarousel').hide();
}
});
This process should be straightforward - click to display, click again to hide... but it's not working as intended
Issue
When I click the check box using the provided code to reveal the hidden section, it displays. However, when I click the check box again to uncheck it, the item remains visible.
Therefore, upon saving the form, assuming the check box remains checked on page reload, we need to ensure the section stays visible:
jQuery
if ($('input[value=carousel_global]:checkbox:checked').attr('id') === "carousel") {
$('.sectionCarousel').show();
}
The solution seems fairly straightforward in function.
The aforementioned issue arises again: even after unchecked the check box, the section remains displayed. Saving the form at this point will temporarily remove the section until the check box is clicked again.
As you can see, this can become problematic.
I pose the question:
before form save
Upon clicking the check box, the hidden section should appear. Clicking again to uncheck it should make the section disappear.
After form save
If the check box was previously clicked and saved, the section should remain visible on page reload. Upon unchecking the check box, the content (specifically the section) should disappear.
While the functionality of showing works, the disappearing action does not. Why?