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

180
Views
¿Cómo deshabilito y verifico qué opción elegí en los botones de opción después de enviar el formulario?

Necesito deshabilitar los botones de opción y mostrar el botón de opción elegido marcado después del envío del formulario. Por lo tanto, después de enviar el formulario, el usuario puede ver el botón de opción marcado, pero no puede cambiarlo sin restablecerlo. ¿Cómo puedo hacer esto?

 <form th:action="@{/addRating}" th:object="${ratings}" method="post"> <div class="wrapper"></div> <div> <input class="input"type="radio" id="rCorrect" name="rg1" value="+1" th:field="*{ratingValue}"> <label for="rCorrect" class="fas fa-star fa-xl" ></label>Rate as a correct answer </div><br> <div> <input class="input" type="radio" id="rWrong" name="rg2" value="-1" th:field="*{ratingValue}"> <label for="rWrong" class="fas fa-star fa-xl"></label>Rate as a incorrect answer </div> <input class="Danger" type="reset" value="Reset"> <input type="submit" value="Submit"> </form>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede agregar el atributo deshabilitado a los botones de radio que no están seleccionados. Debe hacer esto después de enviar el formulario.

Sería algo como esto:

 let uncheckedRadioButtons = document.querySelectorAll('input[type="radio"]:checked'); for(let radioBtn of uncheckedRadioButtons){ radioBtn.setAttribute("disabled", "") }
about 4 years ago · Juan Pablo Isaza Report

0

Debe deshabilitar los elementos del formulario usando el evento javascript "onSubmit".

 //non jQuery mode var form = document.getElementsByTagName("form"); form.addEventListener("submit",function(event){ var inputs = form[0].getElementsByTagName("input"); for( var i=0; i<inputs.length; i++){ var this_input = inputs[i]; if( this_input.type=="radio") { this_input.disabled = true; } } }); //jQuery Mode $("form").on("submit",function(){ $(this).find('input[type="radio"]').prop("disabled",true); });

ACTUALIZACIÓN: si el formulario no se envía a través de AJAX (que creo que es el caso), entonces debe hacerlo en el servidor. debe escribir el HTML del formulario precompletado con la respuesta correcta y con el atributo "deshabilitado" o "solo lectura" configurado en todas las entradas de radio y también el botón de envío debe configurarse como "deshabilitado" para evitar enviar de nuevo. En el botón de reinicio, en este caso, debe agregar EventListener en javascript para volver a habilitar el envío y los botones de opción.

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!