Forum Moderators: open
I was wondering if anybody knew if it was possible to check to see if there was at least a selection made (not which one) without having to go through all the radio buttons?
something like this:
if(document.form.group1.value!=""){};
Yeah, I have lots of radio buttons for this form I'm constructing, and I'm trying to make my code as efficient as possible.
I did figure out something below that works:
...
else if(!(document.q.q316[0].checked¦¦document.q.q316[1].checked¦¦document.q.q316[2].checked¦¦document.q.q316[3].checked¦¦document.q.q316[4].checked)){alert("Please select field 316.");return false}
...
Now I'm just wondering if I can do something along the lines of this:
...
else if(!(document.q.q316[0-4].checked)){alert("Please select field 316.");return false}
...
Anyone know if something like this would be possible? Thanks.
I did figure out something below that works:else if(!(document.q.q316[0].checked¦¦document.q.q316[1].checked¦¦document.q.q316[2].checked¦¦document.q.q316[3].checked¦¦document.q.q316[4].checked)){alert("Please select field 316.");return false}
IMHO, that's a bits nuts. It is isn't efficient is any sense - speed or amount of code.
document.q.q316[0-4].checked
Not possible.
Why not just loop the buttons?
function getRadioSelection(group)
{
for(var k=0;k<group.length;k++)
if(group[k].checked)
return group[k].value;
}
...
getRadioSelection(document.q.q316);