• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inconsistency in radiobutton

 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would have to do something like this:



Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic