Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display value of 'checked' radio button

 
Aparna Ram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • 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.
 
Tak Ng
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Alim Atar
Ranch Hand
Posts: 102
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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
 
sharath kumar s
Greenhorn
Posts: 1
Java Oracle
  • Mark post as helpful
  • send pies
  • 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>










 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic