I have one form and in that form I have many checkboxes and that checkboxes are categorised it in 2 category and when I select one category all its subcategory checkbox get selected automatically and I used On submit button as filter which filter the options according to chekbox selected.
For Ex:-
I have check-boxes as
1]Alcoholic Drinks
2]--Beer
3]--Rum
4]--Whiskey
5]Non Alcoholic Drinks
6]--Coffee
7]--Tea
8]--Juice
I am using jquery to check-box get selected automatically.
Suppose user ticks on Alcoholic then automatically its subcheckbox get selected.
My Code:-
$('#Alcoholic').click(function()
{
if( $(this).attr("checked"))
{
$(this).parents('.min-form').find('label.Beer').removeClass('checked');
$(this).parents('.min-form').find('label.Wine').removeClass('checked');
$(this).parents('.min-form').find('label.Spirits').removeClass('checked');
}
else
{
$(this).parents('.min-form').find('label.Beer').addClass('checked');
$(this).parents('.min-form').find('label.Wine').addClass('checked');
$(this).parents('.min-form').find('label.Spirits').addClass('checked');
}
return false;
});
when I check alcoholic and its sub checkboxes get selected automatically.My problem is that when I submit the form which do not have any action the checkboxes get unchecked automatically.I don’t know how this happens ?? why checkboxes get unselected automatically when I submit form which dont have any action in form tag???
When you don’t have any actions in the form, it just reloads the page – hence the empty checkboxes.
If you add
to your coding when the submit button is clicked, it will keep the form from submitting (to nothing) and so the page from refreshing.