permaculture playing cards*
The moose likes JSF and the fly likes Display value of  'checked' radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Display value of  Watch "Display value of  New topic
Author

Display value of 'checked' radio button

Aparna Ram
Ranch Hand

Joined: Jan 27, 2006
Posts: 59
Hi,

I have 3 radio buttons on my jsp page and I would like the value of the radio button that has been selected, to be alerted in a pop-up message.

This is my code:

JSP,


Action class,

The pop-up returns 'undefined'. Where am I going wrong? Kindly help.
Tak Ng
Greenhorn

Joined: Jun 05, 2007
Posts: 19
The checked property sets or returns whether or not a radio button is checked.
It does not give you the value of your radio button.
Aparna Ram
Ranch Hand

Joined: Jan 27, 2006
Posts: 59
Ok, even this code returns the same.



In fact if I comment all other lines except the one containing 'alert', it returns 'undefined'. And if I uncomment all of it, it returns just nothing.

I don't understand where I am going wrong here.! Please help.
[ July 01, 2007: Message edited by: Aparna Ram ]
Alim Atar
Ranch Hand

Joined: Oct 06, 2006
Posts: 102

hi,

if you want get selected value then use valueChangeListener attribute in <h:selectOneRadio...> and then get value from that event

for example

<<h:selectOneRadio id="searchType" value="#{searchAction.searchType}" valueChangeListener="javascript:checkSearchType(ValueChangeEvent event);" >
f:selectItem itemValue="0" itemLabel="A"
f:selectItem itemValue="1" itemLabel="B"
f:selectItem itemValue="2" itemLabel="C"
</h:selectOneRadio>

In chechSearchType you can get new value from event.getNewValue();

hope this will solve your problem..
Regards
-Alim


Regards,
Alim

SCEA/OCMJEA Part1,SCBCD1.5,SCWCD1.4,SCJP1.4,SQL(Z007)
sharath kumar s
Greenhorn

Joined: Sep 02, 2011
Posts: 1


The below JS should help.........


function checkSearchType()
{
for(var i=0;i<=document.getElementsByName("msForm:searchType").length;i++){
if(document.getElementById("msForm:searchType")[i].checked){
searchType= document.getElementById("msForm:searchType")[i].value
}
}

alert("searchType "+searchType);
}

<h:form id="msForm">
<h:selectOneRadio id="searchType" layout="pageDirection" value="#{searchAction.searchType}" styleClass="tabBold" onClicking="javascript:checkSearchType();">
f:selectItem itemValue="0" itemLabel="A"
f:selectItem itemValue="1" itemLabel="B"
f:selectItem itemValue="2" itemLabel="C"
</h:selectOneRadio>
</h:form>










 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display value of 'checked' radio button
 
Similar Threads
h:selectOneRadio is rerendering panels inconsistently
How to create default value for radio button
Adding space between Radio button and Label
Radio
How to make one of the Radio button default selected