What is wrong in following jquery code ? If the menu
which contains value 1
is selected, at least one submenu
must be checked.
It is not working, if submenu is checked, still it alert message and is stopping. I am trying adding [name='submenu[]']
or storing value in variable
but it doesn't work.
if ($("[name='menu[]']:checked").val() == 1) {
if ($("[name='submenu[][]']:checked").length == 0) {
alert('Select at least one submenu ');
return false;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li><input type="checkbox" name="menu[]" value="1">News
<ul>
<li><input type="checkbox" name="submenu[1][]" value="1">Local</li>
<li><input type="checkbox" name="submenu[1][]" value="2">National</li>
</ul>
</li>
<li><input type="checkbox" name="menu[]" value="2">Views</li>
<li><input type="checkbox" name="menu[]" value="3">Comment</li>
</ul>
Aucun commentaire:
Enregistrer un commentaire