Link to home
Start Free TrialLog in
Avatar of onaled777
onaled777Flag for United States of America

asked on

Length of a radio group being returned as undefined when there is only one radio button in the group

The radio.length value returns 'undefined' when there is only one value in a radio group.  

I know it is not normal to have just one value in the radio group, but I find myself in that situation where the number of radio buttons in the group depends on the output of a query.

Anyone knows how I can work around this issue.


JAVASCRIPT FUNCTION:
 
<script type="text/javascript">
	function getRadioValue(radio) {
	    for(i=0; i<radio.length; i++) {
	        if(radio[i].checked) return radio[i].value;
	    }
	    return 0;
	}
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
glad to help