• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inconsistency in radiobutton

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would have to do something like this:



Eric
 
reply
    Bookmark Topic Watch Topic
  • New Topic