Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda