April 10th, 2008 at 12:14 pm

Get radio button value in JavaScript

Here’s how to get the currently checked value of radio button section. The parameter elementName is the name attribute of the radio input.

function getRadioValue(elementName)
{
	var i, element = document.getElementsByName(elementName);
 
	for (i = 0; i < element.length; i++)
		if (element[i].checked == true)
			return element[i].value;
}