Display value of 'checked' radio button

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,

[CODE]<h:form id='msForm'>

function checkSearchType()

{

alert(document.getElementById('msForm:searchType').checked);

}

<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>[/CODE]

Action class,

[CODE]private String searchType = null;

public String getSearchType() {

return this.searchType;

}

public void setSearchType(String a_iSearchType) {

this.searchType = a_iSearchType;

}[/CODE]

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

[1039 byte] By [aparna_ra] at [2007-11-27 9:12:31]
# 1

Hi,

I dont know whether it helps or not but try using onChange instead of onClick...

I faced a problem using radio button in datatable where onchange could not be used to trigger Javascript as the radio buttons were not part of the same group....so I have to use onclick...

In your case they are part of the same group so onchange must work...Also check whether the Id that you use in your javascript is the same generated for the Radio button Component

Thanks

Avner

avnera at 2007-7-12 21:59:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I recommend to get through some JS/DOM books/tutorials at first (example: http://www.w3schools.com/htmldom/default.asp ). The 'onclicking' attribute doesn't exist, the 'checked' operator only returns a booleanvalue whether the given element is checked (and only if the element supports this property; if it doesn't, then it returns 'undefinied'). And hardcoding the element ID can be avoided by gently passing the 'this' reference to the function.

BalusCa at 2007-7-12 21:59:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...