• 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

Display value of 'checked' radio button

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 102
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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>










reply
    Bookmark Topic Watch Topic
  • New Topic