Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

selectOneRadio - javascript get value

 
Jolie Lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i retrieve value of a radio button (h:selectOneRadio) in a h ataTable using javascript?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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)
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Mike Mentzer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome man!!! my problem is also solved..
 
Shruthi Sam
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • 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.
 
Selvakumar Nachimuthu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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....
 
Toyan Harvey
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic