GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes inconsistency in radiobutton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "inconsistency in radiobutton" Watch "inconsistency in radiobutton" New topic
Author

inconsistency in radiobutton

jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
hi i have form with a bunch of radiobuttons with the name projectName, I found out that if there's only one radiobutton with this name, then xForm.projectName.length is undefined. If there are multiple radiobuttons with this name, then its defined. What's wrong???
thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61314
    
  66

When you have a single radio element, the reference resolves to the single radio element. When you have multiple radio elements with the same name, the reference resolves to a list of the elements. Thus, no length property when you only have one.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
so if i want to write a javscript function to loop through the list of radios on my page(to validate to see if one of them is checked). do people just usually loop through all elements of the form instead of looping through the radio element identified by the radio name?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61314
    
  66

It's rather unusual to have only one radio button on a UI. What would be the point? The whole point of radio buttons is to select one of many. For a single choice, a check box is customarily used. So it's probably not an issue that many worry about.
jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
If the page is dynamic, the case where there's only one radiobutton happens frequently. eg. I list a list of projects and I can only select one to proceed, and it just so happens that at the moment i have only one project.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You would have to do something like this:



Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inconsistency in radiobutton