jeudi 23 février 2017

how to write .onclick method in jquery for all checkbox

I have checkbox in my project which coming from database dynamically. Here i put only one but it could be many depends upon database table entnry.

<div class="checkbox">
   <label class="lbl-cat"><input type="checkbox" value="<?php echo $row["id"]; ?>"                name="category" class="category">  
<?php echo $row["name"]; ?></label>
</div>

I want to fire onclick event using jQuery when user click any of the checkbox. i Try but it is only fire when i click on first checkbox. here is code which i try..

$("[type=checkbox]").click(function () {

                var category_array = new Array();
                var size_array = new Array();
                var color_array = new Array();
                $.each($("input[name='category']:checked"), function() {
                  category_array.push($(this).val());

                });
});

can anyone have idea why it is not working ?? Thanks in advance :)




Aucun commentaire:

Enregistrer un commentaire