Akhila Prakash
Akhila Prakash

Reputation: 481

Jquery disable is not working

<!DOCTYPE html>
<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<script>
$(document).ready(function () {
    $("input[name='data[Store][id][]']").change(function () {
if ($("input[name='data[Store][id][]']").is(':checked')) {
        var input_value = parseFloat($(this).val());
        var brand= $(this).closest('tr').find('#brand').text();


        var number1 = $(this).closest('tr').find('input[name="data[store][stock_received][]"]').attr('disabled', 'disabled');

        }else{
        var number1 = $(this).closest('tr').find('input[name="data[store][stock_received][]"]').prop("disabled", false);

        }

 });
});
</script>
<table style="width:100%">
  <tr>
    <td>Jill</td>
    <td>Smith</td>      

  </tr>
  <tr>
    <td><input id='tmpid' name="data[store][stock_received][]" ></td>       
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
    <tr>
    <td><input id='tmpid' name="data[store][stock_received][]"></td>        
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
  <tr>
    <td><input id='tmpid' name="data[store][stock_received][]"></td>        
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
  <tr>
    <td><input id='tmpid' name="data[store][stock_received][]"></td>        
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
  <tr>
    <td><input id='tmpid' name="data[store][stock_received][]"></td>        
    <td><input type='checkbox' name='data[Store][id][]'></td>
  </tr>
</table>

</body>
</html>

jquery disable is not working properly and I want to disable id=tmpid near near name='data[Store][id][]'. Currently i m using name='data[store][stock_received][]' name near name='data[Store][id][]'. For individual check box its working fine . If I select all then i uncheck then its not working properly

Upvotes: 0

Views: 92

Answers (1)

roshan
roshan

Reputation: 2510

1)ID should be unique

2)You are using parseFloat() on an string

3)$("input[name='data[Store][id][]']").is(':checked') seems in correct should be $(this).is(":checked")

$(document).ready(function() {
  $("input[name='data[Store][id][]']").change(function() {
    if ($(this).is(':checked')) {
      var input_value = $(this).val();
      var brand = $(this).closest('tr').find('#brand').text();


      var number1 = $(this).closest('tr').find('input[name="data[store][stock_received][]"]').attr('disabled', 'disabled');

    } else {
      var number1 = $(this).closest('tr').find('input[name="data[store][stock_received][]"]').prop("disabled", false);

    }

  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table style="width:100%">
  <tr>
    <td>Jill</td>
    <td>Smith</td>

  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
  <tr>
    <td>
      <input class='tmpid' name="data[store][stock_received][]">
    </td>
    <td>
      <input type='checkbox' name='data[Store][id][]'>
    </td>
  </tr>
</table>

Upvotes: 1

Related Questions