function myFunction() { var radios = document.querySelectorAll('input[type=radio]'); var switching_point = 9999; for (i = 0; i < radios.length; ++i) { var radio = radios[i]; let choice = js_vars.choice; if (choice == 1){ if (radio.value == 'left' && radio.checked) { $('#switching_point').val(radio.dataset.amount); break; } else { $('#switching_point').val(9999); } } else{ if (radio.value == 'right' && radio.checked) { $('#switching_point').val(radio.dataset.amount); break; } else { $('#switching_point').val(9999); } } } switching_point = document.getElementById("switching_point").value if (switching_point==0 || switching_point==9999){ alert("You have made the dominated option, please double check your answer!"); return false; } else{ return true; } };