aspose file tools*
The moose likes JSF and the fly likes selectOneRadio - javascript get value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "selectOneRadio - javascript get value" Watch "selectOneRadio - javascript get value" New topic
Author

selectOneRadio - javascript get value

Jolie Lee
Ranch Hand

Joined: May 08, 2005
Posts: 87
how can i retrieve value of a radio button (h:selectOneRadio) in a h ataTable using javascript?


Jys<br /><a href="http://jy-s.com" target="_blank" rel="nofollow">http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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")


GenRocket - Experts at Building Test Data
Jolie Lee
Ranch Hand

Joined: May 08, 2005
Posts: 87
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: May 08, 2005
Posts: 87
yes, tat's wat i tried and i got undefined....

(forgot to change the name when i copy and paste)
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
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 ]

- Varun
Jolie Lee
Ranch Hand

Joined: May 08, 2005
Posts: 87
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 ]
Mike Mentzer
Greenhorn

Joined: Dec 02, 2009
Posts: 2
Awesome man!!! my problem is also solved..
Shruthi Sam
Ranch Hand

Joined: Jul 09, 2008
Posts: 73
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.
Selvakumar Nachimuthu
Greenhorn

Joined: Jan 10, 2011
Posts: 4
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....
Toyan Harvey
Greenhorn

Joined: Feb 15, 2010
Posts: 4
Thank You
 
 
subject: selectOneRadio - javascript get value