Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-09
2
Medium Priority
?
403 Views
Last Modified: 2008-10-10
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

0
Comment
Question by:onaled777
  • 2
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 1000 total points
ID: 22683753
function getRadioValue(radio) {
   if("undefined"==typeof(radio.length) )
   {
     if(radio.checked)
      return radio.value;
   }
   else
   {
          for(i=0; i
0
 
LVL 82

Expert Comment

by:hielo
ID: 22684867
glad to help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question