Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
no se pueden bloquear campos cuando el botón de verificación está marcado

Creé una función donde bloqueo todas mis entradas (lo hice con for of loop). Ahora me gustaría agregar una condición si el botón está marcado desbloquear, si no está marcado bloquear.

Escribí el siguiente código:

 <div class="container"> <input type="number" class="block"> <input type="text" class="block"> <input type="email" class="block"> <input type="checkbox" id="scale1" name="scales"> <label for="scales">Scales</label> </div>
 function blockFileds() { let inputsForm = document.getElementsByClassName('block'); let checker = document.getElementById('scale1'); for (const singleField of inputsForm) { if (checker.checked) { singleField.disabled = false; } else { singleField.disabled = true; } } } blockFileds()

la entrada está bloqueada, pero no puedo desbloquearla.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Por aquí...

 const inputsForm = document.querySelectorAll('input.block') , checker = document.querySelector('#scale1') ; blockFileds() checker.onclick = blockFileds function blockFileds() { inputsForm.forEach( singleField => { singleField.disabled = !checker.checked }) }
 .block, label { display : block; margin : .3em 0; }
 <div class="container"> <input type="number" class="block"> <input type="text" class="block"> <input type="email" class="block"> <label> <input type="checkbox" id="scale1" name="scales"> Scales </label> </div>

about 4 years ago · Juan Pablo Isaza Report

0

Elimine los elementos de la función y adjunte addEventListener a la entrada

 let inputsForm = document.getElementsByClassName('block'); let checker = document.getElementById('scale1'); function blockFileds() { for (let singleField of inputsForm) { if (checker.checked) { singleField.disabled = false; } else { singleField.disabled = true; } } } blockFileds() checker.addEventListener("click", (e)=>{ blockFileds() })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!