Sine Burridge Sine Burridge - 1 year ago 70
jQuery Question

Disabled input until check box is selected

I've got a form input with a prepended check box and I want this input to be disabled until the checkbox is selected. How would I go about doing this?

This is my input:

<div class="form-group ">
<label class="control-label" for="date">Student</label>
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox">
<input id="prependedcheckbox" name="prependedcheckbox" class="form-control"
type="text" placeholder="">

This is an example of the disabled state I'm talking about.

Answer Source

Here is how you do it with JQuery(Remember to add an id to the checkbox):

$(function() {
  $inp = $("#prependedcheckbox");
  $cb = $("#checkbox");
  $inp.prop('disabled', true);

  $cb.on('change', function() {
    if ($':checked')) {
      $inp.prop('disabled', false);
    } else {
      $inp.prop('disabled', true);



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download