当用户选择“其他”时显示文本框如何赋值以及刷新页面时保留值
有一个下拉菜单,其中有一组帐号和“其他”选项。用户可以选择任何帐户,也可以使用“其他”选项输入新帐户。我有这样的代码:
<td>1. Member Account Number<span class="bodyCopy"><font color="#ff0000"> * </font></span>:
<html:select name="DataForm" property="accountNumber" styleClass="formContent" style="width:80px" onchange="toggleField(this.value);">
<html:options 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 函数如下
<script type="text/javascript">
function toggleField(value)
{var a = document.getElementById('Other');
(value == 'Other')? a.style.display = 'block' : a.style.display = 'none';}
我的问题是, 1)当我选择其他时,文本框显示-好。但是如何将值分配给 accountNumber 呢?当我点击提交时,它没有识别出无效的帐号。 2)当页面刷新并出现验证错误时,如何保留值“other”和包含输入数字的文本框?感谢您对此的意见。
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"><font color="#ff0000"> * </font></span>:
<html:select name="DataForm" property="accountNumber" styleClass="formContent" style="width:80px" onchange="toggleField(this.value);">
<html:options 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在混合 html 字段和 struts 字段。我认为对于您的输入字段,您需要使用:
You are mixing html fields and struts fields. I think for your input field you need to use: