Home » Php » javascript – How to send the value of a checkbox?

javascript – How to send the value of a checkbox?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a table that I created with the library of jquery.tabledit.js and I am new to this and in the table I show a checkbox here is the code

<?php
    require ('recursos/conexion.php');



    $page = isset($_GET['p'])? $_GET['p'] : ''
;   if ($page=='view') {

        $sql = "exec sp_sys_nom_autoriza2 'A30',1";
        $stmt = sqlsrv_query($conexion, $sql);
      $select =  "select * from sysnom_nomina_det_tmp where suc = 'A30'";
      $stm = sqlsrv_query($conexion, $select);
        $totalVU = sqlsrv_num_rows($stm);     
       while($row = sqlsrv_fetch_array($stm, SQLSRV_FETCH_ASSOC)) {

         if ($row['notas'] !== "AHORRO" ) {
              if ($row['notas'] !== "PRESTAMO DE AHORRO") {
         ?>
        <tr  style="width:1900px" >

          <td style="width:80px;"><?php echo $row["ID"]?>     </td>
          <td style="width:100px;"><?php echo $row["suc"]?>     </td>
          <td style="width:141px;"><?php echo $row["nombre"]?>  </td>
          <td style="width:141px;"><?php echo $row["depto"]?>   </td>
          <td style="width:141px;"><?php echo $row["percepcion"]?></td>
          <td style="width:141px;"><?php echo number_format($row["monto"], 2, '.', '')?></td>
          <td style="width:141px;"><?php echo $row["notas"]?>   </td>
<?php
          $autorizar = rtrim($row['autorizar']);
           if ($autorizar == 1) {
                         echo "<td id='autorizar'><input type ='checkbox' name='checkbox' id='checkbox' value='1' style='width:30px; height:30px;' checked></td>";
                         $aut=1;
                      }else{
                         echo "<td id='autorizar'><input type ='checkbox' name='checkbox' id='checkbox' value='0' style='width:30px; height:30px;'></td>";
                         $aut=0;
                      }

    }  
  }
}
}else{

  header('Content-Type: application/json');
    $input = filter_input_array(INPUT_POST);

    if ($input['action'] === 'edit') {
            $actualizar ="UPDATE sysnom_nomina_det_tmp SET monto='".$input['Monto']."', autorizar='' where ID='".$input['ID']."' AND suc = '".$input['Sucursal']."' ";
            $resul = sqlsrv_query($conexion, $actualizar);
              if(!$resul){
                echo "Error al Actualizar";
              } else {
                 echo "Datos Actualizados";
              }

        }
    echo json_encode($input);
  sqlsrv_close($resul);
}
?>

there is the checkbox in the table and then when I activate the edit button I send the fields that I’m going to catch to send them in a query this is the html code

 <div class = "contenedor" style="width: 1120px; ">
      <table id="tabledit" class="table ">
          <thead>
              <tr style= "width:1400px;">

                  <th style= "width:80px;">N°</th>
                  <th style= "width:100px;">Sucursal</th>
                  <th style= "width:141px;">Nombre</th>
                  <th style= "width:141px;">Departamento</th>
                  <th style= "width:141px;">Percepcion</th>
                  <th style= "width:141px;">Monto</th>
                  <th style= "width:141px;">Notas</th>
                  <th style= "width:141px;">Autorizar</th>  
              </tr>
          </thead>
          <tbody>

          </tbody>
      </table>  
    </div>
  </div>
</form>

  <script src="../js/hola.js"></script>
  <script src="../js/bootstrap.js"></script>
  <script src="../js/jquery.tabledit.js"></script>
  <script src="../js/buscar.js"></script>

  <script>

  function viewData(){
    $.ajax({
      url: '../A30.php?p=view',
      method: 'GET'
    }).done(function(data){
      $('tbody').html(data)
      tableData()
    })
  }
  function tableData(){
    $('#tabledit').Tabledit({
      url:'../A30.php',
      eventType: 'dblclick',
      editButton : true, 
      deleteButton : false,

       columns:{
              identifier:[[0,'ID'],[1, 'Sucursal']],
              editable: [[5,'Monto']]

      },
      buttons:{
      style: 'width:150px;',
        edit:{
          class: 'btn btn-sm btn-success' ,
          html: '<span class="fa fa-pencil-square-o" ></span> Editar',
          action: 'edit'
        },
        delete:{
          class: 'btn btn-sm btn-default',
          html: '<span class="glyphicon glyphicon-trash"></span> Trash',
          action: 'delete'
        },
        save:{
          class: 'btn btn-sm btn-info',
          html: '<span class="fa fa-floppy-o  "></span> Guardar'
        },
        restore:{
          class: 'btn btn-sm btn-warning',
          html: 'Restore',
          action: 'restore'
        },
        confirm:{
          class: 'btn btn-sm btn-danger',
          html: 'Confirm'
        },
      },
      onSuccess: function(data, textStatus, jqXHR){
        viewData()
      },
      onFail: function(jqXHR, textStatus, errorThrow){
        console.log('onFail(jqXHR, textStatus, errorThrow)');
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrow);
      },
      onAjax: function(action, serialize){
        console.log ('onAjax(action, serialize)');
        console.log(action);
        console.log(serialize);
      }
    });
  }

  </script>
</body>
</html> 

What I am trying to do is also send you what the checkbox is worth, where it says columns but I don’t know how to send the value and be able to catch it when you select the edit button, someone who can help me would appreciate it very much

How to&Answers: