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

142
Views
¿Quiero restablecer la radio cuando la solicitud ajax sea exitosa?

Boton de radio

 - <form id="form-reset"> @csrf <input type="hidden" id="questionId" value="{{$data->id}}"> <div class="btn btn-group-toggle d-flex flex-column" id="radioDiv" data-toggle="buttons"> <label class="btn btn-secondary mb-2"> <input type="radio" name="options" id="option_a1" class="answer-check-box" data-value="1"> Yes </label> <label class="btn btn-secondary"> <input type="radio" name="options" id="option_a2" class="answer-check-box" data-value="2"> NO </label> </div> </form>

codigo js

 function clearRads() { var radList = document.getElementsByName("options"); for (var i = 0; i < radList.length; i++) { if (radList[i].checked) { document.getElementById(radList[i].id).checked = false; } } }

Función de éxito de Ajax

 success: function(response) { // console.log(response.data); timeReset(); let theInput = document.getElementById('questionId'); if (response.data && !(response.data.correct_answer == 0)) { clearRads(); theInput.value = response.data.id; $('#question').html(response.data.question); } else { $('#quesDiv1').html('<h4 class="text-center">Please Wait</h4>'); } }

El problema es que cuando llamo a este clearRads() esto no restablecerá el valor. Esta función devuelve lo indefinido cuando consola.log esta función. gracias de antemano. Por favor orienteme se lo agradecere.

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

0

Su función clearRads() necesita un poco de trabajo.

Entonces, en lugar de lo que tienes, creo que esto debería funcionar:

 function clearRads() { var radList = document.getElementsByName("options"); for (var i = 0; i < radList.length; i++) { radList[i].checked = false; } } }

No es necesario verificar si está borrando todos los cheques. Además, no es necesario document.get... ya que ya tiene esos elementos en la matriz.

Déjame saber cómo va eso.

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!