I have a 5-question form, where the questions are shown one at a time to the user, like a quiz. Question 1 uses input type="radio"
. I would like to know if there is a way not to have to call the function checkObjective()
for each input, and thus avoid repetitions.
My current code is working and this is it:
<form class="questions_box formulario" action="enviar-landing-page-v3.php" method="post">
<div id="question-1">
<h3>The question is: ... ?</h3>
<input type="radio" name="objetivo" id="question-1-answer-a" value="1" required oninput="checkObjective()" /> Answer 1.<br />
<input type="radio" name="objetivo" id="question-1-answer-b" value="2" oninput="checkObjective()" /> Answer 2.<br />
<input type="radio" name="objetivo" id="question-1-answer-c" value="3" oninput="checkObjective()" /> Answer 3.<br />
<div class="text-end mt-3">
<input type="submit" id="submit1" class="btn btn-primary btn-lg" value="Enviar Resposta" style="display: none;" />
</div>
<script type="text/javascript">
function checkObjective() {
if (document.getElementsByName("objetivo").value == "") {
document.getElementById("submit1").style.display = "none";
} else {
document.getElementById("submit1").style.display = "block";
}
}
</script>
</div>
</form>