Check if one radio option was chosen
Login or Register to Bookmark this snippet
This function checks that a radio option was selected from a group. Handy for form validation.
Requires xGetElementsByTagName (also available on this site).
function checkOneRadioSelected(elm,msg) {
if (elm) {
if(typeof(elm)=='string') {
elm = xGetElementById(elm);
}
var f = searchUp(elm,'form');
var ins = xGetElementsByTagName('input',f);
for (i=0;i<ins.length;i++) {
if (ins[i].type.toLowerCase() == 'radio' && ins[i].name == elm.name && ins[i].checked) {
return true;
}
}
if (msg) {
alert(msg);
}
}
return false;
}
Added by JC on 12th November, 2007
There are no comments about this snippet.
You must be registered and logged in to post a comment.
Login here to post a comment