I am still pretty new to jQuery, so forgive me if this doesn’t make sense the first round.
I have a set of checkboxes (allowed, not allowed, negotiable), that if you check allowed or negotiable it unhides another set of checkboxes via the onclick event.
The problem I am having is that when the page is refreshed, I want the second set of checkboxes to be visible if allowed or negotiable are checked. I’d like this to be done on page load, not through any click or change events if possible.
I have tried various suggestions to other issues with no luck.
eg: if ($("#id_pets_0").attr("checked")==true)
Is this possible?
If anyone has any alternatives to this, I’m game for that as well.
UPDATE:
This is what I have been attempting.
$(function() {
if ($("#id_pets_0").attr("checked")==true) {
$("#dogs").show();
$("#cats").show();
}
else {
$("#dogs").hide();
$("#cats").hide();
}
});
UPDATE:
This code does work. So I know that it is checking the checkboxes for the click events at least.
$(function() {
$('input#id_pets_0').click(function() {
if ($(this).attr("checked")) {
$("#id_pets_1").attr("checked", false);
$("#dogs").show("slow");
$("#cats").show("slow");
return;
}
if ($("#id_pets_2").attr("checked")) {
$("#dogs").show("slow");
$("#cats").show("slow");
}
else {
$("#id_dogs_0").attr("checked", false);
$("#id_dogs_2").attr("checked", false);
$("#id_cats_0").attr("checked", false);
$("#id_cats_2").attr("checked", false);
$("#dogs").hide("slow");
$("#cats").hide("slow");
}
});
});
Thanks to all that answered. I would have thought those would have worked.
What I ended up doing was wrapping the show/hide options in a Django template
ifand use the context that was being passed. Since I was capturing the selection ofpetsI was able to then use theifto show or hide thecatsanddogsselection section.