Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
how to disable and enable textbox when a checkbox is checked

I have here multiple checkboxes which data is from the database. I want that the textbox will be remained disable until I checked or clicked the checkbox. lets just say this is the data that came from the database for example.

$(function() {
  $('.check').click(function() {
    if ($(this).is(':checked')) {
      $('.checks').removeAttr('disabled');
      $('.checks').focus();
    } else {
      $('.checks').attr('disabled', 'disabled');
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" class="check"> Aldrin
<input type="text" class="checks" disabled>

<input type="checkbox" class="check"> Dafne
<input type="text" class="checks" disabled>

<input type="checkbox" class="check"> Diane
<input type="text" class="checks" disabled>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Sure, you can reduce what you have to just the following, using $(this) to refer to the specific checkbox you're checking/unchecking:

$(function() {
  $('.check').click(function() {
    $(this).next().prop('disabled', !$(this).is(':checked'))
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" class="check"> Aldrin
<input type="text" class="checks" disabled>

<input type="checkbox" class="check"> Dafne
<input type="text" class="checks" disabled>

<input type="checkbox" class="check"> Diane
<input type="text" class="checks" disabled>

about 4 years ago · Juan Pablo Isaza Relatório

0

$(function() {
  $('.check').click(function() {
    if ($(this).is(':checked')) {
      $(this).next('.checks').removeAttr('disabled');
      $(this).next('.checks').focus();
    } else {
      $(this).next('.checks').attr('disabled', 'disabled');
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" class="check"> Aldrin
<input type="text" class="checks" disabled>

<input type="checkbox" class="check"> Dafne
<input type="text" class="checks" disabled>

<input type="checkbox" class="check"> Diane
<input type="text" class="checks" disabled>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda