aspose file tools*
The moose likes Struts and the fly likes text box displays when user select “Other” how to assign the value and retain the value when refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "text box displays when user select “Other” how to assign the value and retain the value when refresh" Watch "text box displays when user select “Other” how to assign the value and retain the value when refresh" New topic
Author

text box displays when user select “Other” how to assign the value and retain the value when refresh

raj mal
Greenhorn

Joined: Feb 11, 2011
Posts: 11
have a dropdown where i have set of account numbers and an option of "Other". user can select any account or they can user "Other" option to enter a new account. I have the code like this:
<td>1. Member Account Number<span class="bodyCopy"> * </span>: <html:select name="DataForm" property="accountNumber" styleClass="formContent" style="width:80px" onchange="toggleField(this.value);"> <htmlptions collection="<%= WorkConstants.TEST1 %>" property="value" labelProperty="label" styleClass="formContent"/> <option value="Other">Other </option> </html:select> <input type="text" id="Other" value="accountNumber" name="accountNumber" style="display:none;" maxlength="9" size="9" > </td>

Togglefield function is as below

<script type="text/javascript"> function toggleField(value) {var a = document.getElementById('Other'); (value == 'Other')? a.style.display = 'block' : a.style.display = 'none';}

My question is, 1) when I select other, the text box displays- good. But how to assign the value to accountNumber ? when I click submit, it is not recognizing getting invalid account number. 2) When the page refreshes with validation errors, how do I retain value "other" and the text box with the number that is entered? appreciate your input on this.
Chris Montgomery
Ranch Hand

Joined: Jan 14, 2004
Posts: 141
I've stumbled through this same issue during validation. I add a hidden form field and preserve the value there.

One catch... I only encounter this when doing an AJAX call (via jQuery in my case). My Action doesn't always have access to the variables in a way that allow me to represent selections, so using jQuery's document.ready implementation I'm able to detect the validation error and use the hidden field to reload the select box since jQuery does have access to the newly entered values.

It doesn't look like you are using jQuery - definitely recommend it. If not possible, there should be enough here to whip something up!

Hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: text box displays when user select “Other” how to assign the value and retain the value when refresh
 
Similar Threads
Ajax, Struts, and a few pesky event based issues
select another dropdown based on a selection from first dropdown in jsp
The program error!
Drop Down value not stored for submit
select another dropdown based on a selection from first dropdown using <html:select> struts tag