Select a checkbox in a table

1

Today I pose the following problem, I have in the view of my website a table with clients that I pull from the database until there everything is fine, at the same time as the clients I have a checkbox select so that when I want upload a file can select several users to which I'm going to send that file, but when I go through and do a test, it only pulls me first from the list when I select any checkbox in the table, or I select several, in the next I pass the html of the view.

<div class="scroll_vertical">
    <table class="table table-bordered table-striped" id="dtDynamicVerticalScroll" >

        <tbody id="dtDynamicVerticalScroll">
            <tr>
                <th ></th>
                <th ></th> 
            @foreach($clients as $client)
            </tr>
            <tr>
                <td><input type="checkbox"  onclick="return golbat()" name="checkit"  id="cheid"></td>
                <td id="clientetd">{{@client}}</td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>

in the following the function that you use to see that only one of the list comes out but I want to select all possible ones or just one of any position in the table and send the files to you.

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script type="text/javascript">
    function golbat(){
        var take = document.getElementById("clientetd").innerHTML;
        swal("click"+ take);
    }  
</script>
<script>
   $(document).ready(function () {
       $('#dtDynamicVerticalScroll').DataTable({
           "scrollY": "50vh",
           "scrollCollapse": true,
       });
       $('.dataTables_length').addClass('bs-select');
   });
</script>
<style type="text/css">
    div.scroll_vertical {
        height: 280px;
        width: 200px;
        overflow: auto;
        border: 0px solid #666;
        background-color: #ccc;
        padding: 2px;
    }
</style>
    
asked by Rojas Rodriguez Ricardo 29.10.2018 в 18:10
source

2 answers

0

With the class selector , like the example I put below as I see that you are using JQuery in this case although there are no group1 and group2 classes, but they allow me to group and identify checkboxes that have been checked with input: checkbox: checked.group1, without needing an id for each one as in the example that I show next, where I get an arrangement of the values of the checkboxes that have been checked

<!DOCTYPE html>
<html>
  <head>
  <meta charset="UTF-8">
  <title>Ejemplo de selector checkboxes</title>
  <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
  <script>
    	$( document ).ready(function() {
        	var values = $('input:checkbox:checked.group1').map(function () {
  					return this.value;
					}).get();
        	console.log( "valores:" +values);
    	});
	</script>
  </head>
  <body>
    <input type="checkbox" class="group1" value="18" checked="checked" />18 group1 seleccionado<br>
    <input type="checkbox" class="group1" value="20" />20 group1<br>
    <input type="checkbox" class="group1" value="15" />15 group1<br>
    <input type="checkbox" class="group2" value="14" />14 group1<br>
    <input type="checkbox" class="group1" value="55" checked="checked" />55 group1 seleccionado<br>
    <input type="checkbox" class="group1" value="10" checked="checked" />10 group1 seleccionado<br>
    <input type="checkbox" class="group2" value="77" checked="checked" />77 <b>group2</b> seleccionado<br>
    <input type="checkbox" class="group1" value="11" />11 group1<br>
  </body>
</html>
    
answered by 29.10.2018 / 20:00
source
0

Instead of an id, you can use a class

<td class = "claseTD"></td>

and to do the tour you can do the following

    $('.claseTD').each(function(){
       var actual = $(this);
       //hacer lo demas que quieras
     })
    
answered by 29.10.2018 в 18:30