通过Text 来设定 Select Option 缺省值

<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="${f:url('/css/stylesheet.css')}">
<script type="text/javascript">

function add(btn) {
btn.disabled = true;
var frm = document.getElementById("form1");
frm.action += "add";
frm.submit();
}

function change(){
if (event.keyCode == 13){
alert("文字が「" + Myfm.txt.value +"」に変更されました");
}
else
return
}

[color=red]function SetdefaultData(textObj,selectObj){
for(i=0;selectObj.length>i;i++){
<%--alert(frmObj.elements["deptId_test"].value);--%>
if(selectObj.options[i].value == textObj.value){
selectObj.options[i].selected = true;
<%--alert("ttt"+f.options.value);--%>
break;
}else{
selectObj.options[0].selected = true;
}
}
}[/color]


</script>
</head>
<body>
<s:form method="POST" styleId="form1">
<tiles:insert template="/WEB-INF/view/common/layout.jsp" flush="true">
<tiles:put name="content_menu" type="string">
<c:choose>
<c:when test="${id == null}">
<button οnclick="add(this)">登録</button>
</c:when>
<c:otherwise>
<s:submit property="update" value="更新"/>
</c:otherwise>
</c:choose>
</tiles:put>
<tiles:put name="content" type="string">
<div id="content" class="content_scroll">
<html:errors/>
<table class="data" style="width:300px;">
<tr>
<th class="data" style="width: 100px;">ID</th>
<td class="data" style="width:150px;">
${id}<html:hidden property="id"/><html:hidden property="versionNo"/>
</td>
</tr>
<tr>
<th class="data">従業員番号</th>
<td class="data">
<html:text property="empNo" size="12" maxlength="10" errorStyleClass="error"/></td>
</tr>
<tr>
<th class="data">従業員名</th>
<td class="data">
<html:text property="empName" size="26" maxlength="20" errorStyleClass="error"/></td>
</tr>
<tr>
<th class="data">雇用日</th>
<td class="data">
<html:text property="hiredate" size="12" maxlength="10" errorStyleClass="error"/>
</td>
</tr>
<tr>
<th class="data">給与</th>
<td class="data">
<html:text property="sal" size="10" maxlength="8" errorStyleClass="error"/>
</td>
</tr>
<tr>
<th class="data">管理者ID</th>
<td class="data">
<html:text property="mgrId" size="12" maxlength="10" errorStyleClass="error"/>
</td>
</tr>
<tr>
<th class="data">部門名</th>
<td class="data">
<html:select property="deptId">
<option value=""></option>
<html:options collection="deptList" property="id" labelProperty="deptName"/>
</html:select>
</td>
[color=red] <html:text property="deptId_test" size="12" maxlength="10" οnkeydοwn="SetdefaultData(this.form.elements['deptId_test'],document.getElementById('testID'))" οnkeyup="SetdefaultData(this.form.elements['deptId_test'],document.getElementById('testID'))"/>
[/color] </tr>

<tr>
<th class="data">SELECT OPTION</th>
<td class="data">
<html:select property="testID">
<option value="C"></option>
<html:options collection="testList" property="KeyData" labelProperty="ValData"/>
</html:select>
</td>

</tr>
</table>
<html:hidden property="versionNo"/>
</div>
</tiles:put>
</tiles:insert>
</s:form>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值