Created
December 21, 2011 17:36
-
-
Save cesarmiquel/1506907 to your computer and use it in GitHub Desktop.
Return value of selected radio button using Prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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