function myFunction() { var radios = document.querySelectorAll('input[type=radio]'); var switching_point = 9999; let choice = js_vars.choice; let min = js_vars.min; let max = js_vars.max; for (i = 0; i < radios.length; ++i) { var radio = radios[i]; 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 == min ){ document.getElementById("switching_point").value = 0; } };