Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help required with conditional options in a select box

843838May 10 2007 — edited May 12 2007
Hi,

Hoping someone can help me...

I have a JSP that contains a question...

If the user selects 'Yes', I need to display a select box with values a, b, c.

If the user selects 'No', I need to reveal a select box with values a, b & c but with extra values d & e.

At the moment, I have some javascript which works to toggle each box when the answer to the questions changes. Both boxes reference the same property in the bean.

The problem:

I can see that the value selected for each box is being held in memory, and this can result in an incorrect (previously selected) value being sent to the bean's set method.

Can someone help me with this?

Eg. Is there a way of conditionally displaying the options within a select box (that way only one box would be required) or a way of uniquely identifying each box so perhaps the value in memory can be cleared when the user changes their mind?

The boxes are currently defined something like this:
<html:select property="employmentStatus">	
       <html:option value="a">Please select</html:option>	
       <html:option value="b">Employed</html:option>
       <html:option value="c">Self-employed</html:option>
</html:select>

<html:select property="employmentStatus">	
       <html:option value="a">Please select</html:option>	
       <html:option value="b">Employed</html:option>
       <html:option value="c">Self-employed</html:option>
       <html:option value="d">Retired</html:option>
       <html:option value="e">Other</html:option>
</html:select>
(sorry, the real code is at work and I'm home now!)

Any help greatly appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2007
Added on May 10 2007
3 comments
1,047 views