samedi 24 juin 2017

how to check the value of checkboxes in each row of table dynamically using javascript or jquery

I have a table in which values are dynamically added from database as below:

    var row = table.insertRow(i);
i = i+1;
// Insert new cells (<td> elements) at the 1st and 2nd position of the new <tr> element:
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
var cell7 = row.insertCell(6);
var cell8 = row.insertCell(7);
var cell9 = row.insertCell(8);
var cell10 = row.insertCell(9);
var cell11 = row.insertCell(10);

// Add some text to the new cells:
cell1.innerHTML = '$name';
cell2.innerHTML = '$name2';
cell3.innerHTML = '$lastname';
cell4.innerHTML = '$lastname2';
cell5.innerHTML = '$mellicode';
cell6.innerHTML = '$estekhdamnum';
cell7.innerHTML = '$email';
cell8.innerHTML = '$username';
cell9.innerHTML = '$password';
cell10.innerHTML = '$id';
var checkbox = document.createElement('INPUT');
checkbox.type = 'checkbox';
checkbox.name = 'checkbox[]';
checkbox.value = 'i-1';
cell11.appendChild(checkbox);

I would like to add a button at the end of the table that when I click it, it checks all the check boxes, recognizes the row of the checkbox and do some query.

$('tr').click(function(){

}); 

I shouldn't use 'tr' here I think but I don't know how to recognize the check boxes and see if it is checked or not and recognize the row of the checked checkbox.

thanks for your answer in advance.




Aucun commentaire:

Enregistrer un commentaire