mercredi 31 août 2016

Jquery enable/disable checkbox by name

I am trying to disable checkboxes by name in the following table, but it is not working. Any suggestions, why?

<table border="1" class="myTable grid">
  <tr align="center">
    <td>A</td>
  </tr>
  <tr align="center">
    <td>1</td>
    <td>
      <input type="checkbox" name="cb1;1" value="1">
    </td>
  </tr>
  <td>2</td>
  <td>
    <input type="checkbox" name="cb2;1" value="1" checked>
  </td>
  </tr>
  <tr align="center">
</table>
<button id="button1" type="button"> DISABLE </button>
<button id="button2" type="button">ENABLE </button>

This is how I am disable/enable these checkboxes. I have tried .attr('disabled', 'disabled'); for disabling too.

$("#button1").click(function() { 
  var cbname = $j(this).attr("name");
  $("input[name='cbname']").prop("disabled", false);
});

$("#button2").click(function() { 
  var cbname = $j(this).attr("name");
  $("input[name='cbname']").prop("disabled", true);
});




Aucun commentaire:

Enregistrer un commentaire