Disable field by clicking the checkbox

Asked

Viewed 132 times

1

How do I disable a field by clicking the checkbox option?

  • 1

    You can explain the question better and add HTML?

1 answer

2


A simple example to do what you want:

$('#control').on('change', function () {
  $('#target').prop('disabled', $(this).is(':checked'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="checkbox" id="control" />
<input type="text" id="target" />

Note: The library jQuery was used.

  • Thanks Luiz, I had only managed to do the reverse.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.