Skip to content

Instantly share code, notes, and snippets.

@cesarmiquel
Created December 21, 2011 17:36
Show Gist options
  • Save cesarmiquel/1506907 to your computer and use it in GitHub Desktop.
Save cesarmiquel/1506907 to your computer and use it in GitHub Desktop.
Return value of selected radio button using Prototype
/**
* Returns the value of the selected radio button in the radio group, null if
* none are selected, and false if the button group doesn't exist
*
* @param {radio Object} or {radio id} el
* OR
* @param {form Object} or {form id} el
* @param {radio group name} radioGroup
*
* From: http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/
*/
function $RF(el, radioGroup) {
if($(el).type && $(el).type.toLowerCase() == 'radio') {
var radioGroup = $(el).name;
var el = $(el).form;
} else if ($(el).tagName.toLowerCase() != 'form') {
return false;
}
var checked = $(el).getInputs('radio', radioGroup).find(
function(re) {return re.checked;}
);
return (checked) ? $F(checked) : null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment