I have a problem in my JavaScript code.
I have a HTML form in which I use table values that are fetched from Mysql table. I use an array to print my all values in my table. Here is output of my form:
After that I use JavaScript to alert: "Please select at least one opinion (Mutual Fund)."
Here is my code
function checkRatings(){
var checked = [].reduce.call(document.forms[0].opinion, function(current, item) {
if (item.checked) {
current.push(item.value);
}
return current;
}, []);
if (checked=='')
{
alert("Please select at least one opinion");
return;
}
else
document.getElementById("form_id").submit();}
This code working fine when I have multiple opinions (Mutual Fund) just like as above figure, but it's not working when I have only single opinion. As on this image:
In this scenario after I check opinion it gives me the alert again and again and could not proceed it...
Can anyone please help me?