• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

selectOneRadio - javascript get value

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i retrieve value of a radio button (h:selectOneRadio) in a h ataTable using javascript?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same way you do it without using JSF. Only the ID is going to be JSF specific. So if you have a form id of "myForm" and a radio button as "myRadio" you would use

getElementById("myForm:myRadio")
 
Jolie Lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my radio button in jsf


when i view source i see it becomes


therefore, in javascript when i do this:


it gives me "undefined"

anybody can advise me wat's wrong?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, when I said "myform" it was an example. I expected you would use whatever you needed to in place of "myform" in your javascript.

document.getElementById("budgetcategoryform:active").value
 
Jolie Lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, tat's wat i tried and i got undefined....

(forgot to change the name when i copy and paste)
 
Ranch Hand
Posts: 1400
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have never used "value" option but in order to know which button is checked, you can use following option

document.forms['budgetcategoryform']['budgetcategoryform:active'][0].checked

document.getElementById("budgetcategoryform:active")[0].checked
should also work.

Both of above expressions return boolean value.

You can use [1] index also in case you want to. [0]th element refers to first button and [1]th element refers to second button.

P.S. Jolie, if you can format your second post, the readability of the
page can be improved. Currently page is bit stretched out.
[ September 13, 2005: Message edited by: Varun Khanna ]
 
Jolie Lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey, thanks.. it works...but somehow when i trid the one with getElementById, it doesn't work...

oops..sorry...

i post it in the "code" tag....

[ September 14, 2005: Message edited by: Jolie Lee ]
[ September 14, 2005: Message edited by: Jolie Lee ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awesome man!!! my problem is also solved..
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I know this is an old post, but now i need the same requirement. As solution is not posted here, please let me know how we can get a selected radio button value in the javascript. Thanks in advance.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Varun Khanna wrote:I have never used "value" option but in order to know which button is checked, you can use following option

document.forms['budgetcategoryform']['budgetcategoryform:active'][0].checked

document.getElementById("budgetcategoryform:active")[0].checked
should also work.

Both of above expressions return boolean value.

You can use [1] index also in case you want to. [0]th element refers to first button and [1]th element refers to second button.

P.S. Jolie, if you can format your second post, the readability of the
page can be improved. Currently page is bit stretched out.
[ September 13, 2005: Message edited by: Varun Khanna ]






Thanks a ton it works for me too....
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic