jquery - How to check status of Django generated multiple checkbox? -
i know how use jquery save names of selected options django based multiple checkbox? seems not able select group of checkbox... can give me suggestions on code? thanks!
jsfiddle example
html code
<table class="tab_model"> <tbody> <tr> <th> <label for="id_model_0">model:</label> </th> <td> <ul> <li> <label for="id_model_0"> <input type="checkbox" name="model" value="a" id="id_model_0">model a</label> </li> <li> <label for="id_model_1"> <input type="checkbox" name="model" value="b" id="id_model_1">model b</label> </li> <li> <label for="id_model_2"> <input type="checkbox" name="model" value="c" id="id_model_2">model c</label> </li> </ul> </td> </tr> </tbody> </table> <input class="submit" type="submit" value="submit">
jquery
var allvals = []; $('.submit').click(function () { $('input[id^="id_model_"] :checked').each(function () { allvals.push($(this).val()); }); alert(allvals); });
i give boxes class, class='the_checkboxes'
use:
$(".the_checkboxes:checkbox:checked").each(function()({ allvals.push($(this).val()); });
it cleaner (to me, anyway).
Comments
Post a Comment