Bryan Gomez

Bryan Gomez

  • NA
  • 21
  • 36.3k

How to get checkbox status and data value [MVC]

Nov 13 2017 4:57 AM
How to get the checkbox status and data value from my table in HTML? I want to get the @myJob.so_no.
 
Here's my view:
  1. <table class="table table-striped table-hover table-condensed" id="myJobTable">  
  2.                     <thead class="thead-dark">  
  3.                         <tr>  
  4.                             <th scope="col">#</th>  
  5.                             <th scope="col"></th>  
  6.                             <th scope="col">Date</th>  
  7.                             <th scope="col">SO No</th>  
  8.                             <th scope="col">Serial</th>  
  9.                             <th scope="col">Status</th>  
  10.                             <th scope="col">Technician</th>  
  11.                         </tr>  
  12.                     </thead>  
  13.                     @foreach (MyJobAllocation myJob in Model.MyJob)  
  14.                     {  
  15.                         <tr>  
  16.                             <td>@myJob.row</td>  
  17.                             <td>  
  18.                                 <input type="checkbox" id="chk" />  
  19.   
  20.                             </td>  
  21.                             <td>@myJob.date</td>  
  22.                             <td>@myJob.so_no</td>  
  23.                             <td>@myJob.serial</td>  
  24.                             <td>@myJob.status</td>  
  25.                             <td>@myJob.technician</td>  
  26.                         </tr>  
  27.                     }  
  28.                 </table> 
 And for my script:
I'm  trying to print a simple alert if my function is working. But it doesn't.
  1. function asign_to() {  
  2.     var table = document.getElementById("myJobTable");  
  3.     var value_check = "";  
  4.     for (var i = 0; i < table.rows.length; i++) {  
  5.         if ($('#chk')[i].is(':checked')) {  
  6.             alert('You clicked me!');  
  7.         }  
  8.     }  

 Got this error:
  1.   TypeError: $(...)[i].is is not a function

Answers (2)