I had developed a jsp web project, where user has to select one option from radio button, and i m sending the user selected value to other page using javascript.
JavaScript code:
function select() {
var val1 = document.getElementsByName("President");
var result1;
for (var i = 0; i < val1.length; i++) {
if (val1[i].checked) {
console.log(val1[i].checked)
result1 = val1[i].value;
alert(result1);
} else {
alert("president vote is missing");
return;
}
}
}
When the user doesn't choose an option, then javascript code is working fine and it is going to else and showing an alert message that("president vote is missing"). But when user chooses one option from the list then then the if condition is working fine and after that else condition is also getting executed , I never faced this kind of problem
console.log(val1[i].checked)should have a semi-colon - it might be useful to see the markup on this issue perhaps?