Advertisement

05.27.2008 at 08:21AM PDT, ID: 23435129
[x]
Attachment Details

Accessing a struts2 radio button in javascript

Asked by hai_madhan in Java Server Pages (JSP), JavaScript, Jakarta Struts

Tags: Struts 2, IE,

Hi,

I am using struts 2 and facing an issue. I render a radio button with the struts tag like this:

<s:radio name="currnetObject.status" list="statusList" onclick="toggle()"/>

Here, the 'statuslist' is a List (String) of values to be rendered as radio buttons.
The 'currentObject' is the object which holds the form fields being inserted/modified.
'status' is an attribute of the currentObject which has the selected radio button's value.

The radio buttons are rendered properly.  When I select one of the radio button and save the form, the selected value if getting persisted properly. No issues.

The problem starts when I try to do something on the client side when the user chooses one of the radio buttons. I wrote a javascript function called 'toggle'. I'm trying the get the value of the radio choosed.
To do that in side the javascript function, I try to access the radio button like this :
"document.my_form.currentObject.status"  Please note that the name of the radio button is "currentObject.status". But the javascript throws an error as " 'status' is null or not an object".

I understand that javascript breaks because of the priod (".") in the field name. But that's the way to render the radio button using struts 2. Now, how do I access this kind of field names in the javascript function?

Thanks,
Madhan
 

 
 


Start Free Trial
[+][-]05.27.2008 at 09:57AM PDT, ID: 21653519

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.27.2008 at 10:10AM PDT, ID: 21653627

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Server Pages (JSP), JavaScript, Jakarta Struts
Tags: Struts 2, IE, <s:radio name="object.attribute">
Sign Up Now!
Solution Provided By: robacarp
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.28.2008 at 09:05AM PDT, ID: 21661700

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628