how can I set the checked value to a checkbox by clicking on my button

2

$(document).on("ready", function() {
  mostrar2();
});

var mostrar2 = function() {
  var table = $("#tabla").DataTable({
    "ajax": {
      "method": "POST",
      "url": "conection.php"
    },
    "columns": [{
        "data": "id"
      },
      {
        "data": "product"
      },
      {
        "data": "category_id"
      },
      {
        "data": "name"
      },
      {
        "defaultContent": "<button type='button' class='editar btn btn-primary'>Editar</button><button type='button' class='eliminar btn btn-danger' data-toggle='modal' data-target='#modalEliminar' ><i class='fa fa-trash-o'></i></button>"
      }
    ]
  });
  obtener_data_editar("#tabla tbody", table);

}

var obtener_data_editar = function(tbody, table) {
  $(tbody).on("click", "button.editar", function() {
    var data = table.row($(this).parents("tr")).data();
    var Nombre = $("#id").val(data.name),
      Price = $("#nuevo").val(data.category_id);
  });
}
<html>

<head>
  <title>formulario checkbox</title>
</head>

<body>

  <form class="producto">
    <tr>
      <td>

        <div><label>Seccion Nuevo:</label><input id="nuevo" type="checkbox" name="prodnuevo" value=""></div>
      </td>
    </tr>
  </form>
</body>

</html>
    
asked by Eduardo Vanegas 07.06.2017 в 00:09
source

2 answers

0

You can check the check using the .checked attribute. This would be an example of its use:

function check() {
    $("#myCheck").prop('checked', true);
}

function uncheck() {
    $("#myCheck").prop('checked', false);
}
Checkbox: <input type="checkbox" id="myCheck">

<button onclick="check()">Check Checkbox</button>
<button onclick="uncheck()">Uncheck Checkbox</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
answered by 07.06.2017 / 01:01
source
1

with jquery only use .click () in your checkbox

  $('#validar').click(function() {
            $("#nuevo").click(); 
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<label>Seccion Nuevo:</label><input id="nuevo" type="checkbox" name="prodnuevo" value=""></div>


<button id='validar'>check</button>
    
answered by 07.06.2017 в 00:36