dimanche 10 février 2019

Check if checkbox in checkbox array is checked

I have an array of checkboxes. If there is a checked checkbox, it will be added into a string of text. Here is my code:

  var a = $(this).closest('tr').parent().closest('tr').find('input[type="checkbox"].CheckedArray');

        for (var i = 0; i < a.length; i++) {
            if (a[i].is(':checked')) {
                list= list+ a[i].value + ", ";
            }
            alert(list);
        }

        <table id="" class="table">
<tr>
    <td>
        <div class="form-horizontal form-inline">
            <input class="CheckedArray" type="Checkbox" value="' + Id + '" id="CheckedArray" name="CheckedArray" />Select<div class="form-group"><label for="" class="control-label col-sm-1"></label><label for="" class="control-label col-sm-4">PD No: </label><div class="col-sm-3"><input name="PDNo" class="form-control input-sm " id="PDNo" type="text" /></div></div>
        </div>
    </td>
</tr>

I used checked as condition but it doesnt show any alert. I dont want to use filter function because i need the iteration value to shows other input.




Aucun commentaire:

Enregistrer un commentaire