checkbox enable/disable in jquery

823 views Asked by At

I wanna enable input form when I check input checkbox.

<div class="form-group clearfix">
  <input type="checkbox" id="work" class="pull-left" />
  <label for="work" class="form-info pull-left">
  {!! Form::number('work', null, ['class' => 'form-control work','placeholder' => 'Nghề nghiệp'])!!}
  </label>
</div> 

<div class="form-group clearfix">
  <input type="checkbox" id="city" class="pull-left" />
  <label for="city" class="form-info pull-left">
  {!! Form::number('city', null, ['class' => 'form-control city','placeholder' => 'Thành phố'])!!}
  </label>
</div>
2

There are 2 answers

0
Farhad Bagherlo On BEST ANSWER

$("input[type=checkbox]").on("click",function(){
  $("label[for="+$(this).attr("id")+"]").find("input[type=text]").prop( "disabled", (!$(this).is(":checked")) );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group clearfix">
  <input type="checkbox" id="work" class="pull-left" />
  <label for="work" class="form-info pull-left">
   <input type="text" disabled />
  </label>
</div> 

<div class="form-group clearfix">
  <input type="checkbox" id="city" class="pull-left" />
  <label for="city" class="form-info pull-left">
 <input type="text" disabled />
  </label>
</div>

0
Luple On

In order to check if a checkbox is checked, what you can do somethig like this. if you can't get it working let me know and i can help more.

$("#work").on("change", function(){
   var checked = $(this).is(':checked');
   if(checked){
       $("#idofwahteveryouwantdisabled").css("disabled", true);
   }
   else{
       $("#idofwahteveryouwantdisabled").css("disabled", false);
   }
}