0

I have a table form mysql in my html page, and each row has a checkbox, if I checked some checkboxes , how could I output the rows I checked. now I konw how to output all the rows, but I don't konw how to selected the rows I checked

laiqn
  • 53
  • 1
  • 9

2 Answers2

0

give all the check boxes the same name and assign each one with a different value, say the rows primary key.

Use request.getParameterValues() in the servlet and you will get an array which will have only the checked values

divyabharathi
  • 2,187
  • 17
  • 12
0

Have more you can get checked table rows in javascript. Examples:

var allRows = $('#yourTableId tr');
for(var i=0; i<allRows.length; i++) {
   if(allRows[i].find('input:checkbox').checked) {
   //selected row allRows[i]. And you can get value checkbox      allRows[i].find('input:checkbox').value
   }
}

or use each loop jquery:

$('#yourTableId tr').each(function(index)) {
   if($(this).find('input:checkbox').checked) {
       //selected row $(this). And you can get value checkbox   $(this).find('input:checkbox').value
   }
}

And have more answers in stackoverflow for such issues:

Using jquery to get all checked checkboxes with a certain class name

Jquery find a checkbox inside a table row

How to check whether a checkbox is checked in jQuery?

Community
  • 1
  • 1
SBotirov
  • 13,872
  • 7
  • 59
  • 81