Skip to content

Instantly share code, notes, and snippets.

@attebury
Created July 23, 2014 17:36
Show Gist options
  • Save attebury/5f9ba4c6024c7f13384f to your computer and use it in GitHub Desktop.
Save attebury/5f9ba4c6024c7f13384f to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<label>
<input type="radio" name="days" value="15" checked /> 15
</label>
<label>
<input type="radio" name="days" value="30"/> 30
</label>
<label>
<input type="radio" name="days" value="45"/> 45
</label>
</body>
</html>
getSelectedRadioButtonValue = function (radioName) {
var radioButtons,
radiosLength;
radioButtons = document.getElementsByName(radioName);
radiosLength = radioButtons.length;
for (var i = 0; i < radiosLength; i++) {
if (radioButtons[i].checked) {
return radioButtons[i].value;
}
}
};
console.log(getSelectedRadioButtonValue('days'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment