通过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
}
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;
}
}
}
</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 onclick="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" style="width:300px;">
<tr>
<th style="width: 100px;">ID</th>
<td style="width:150px;">
${id}<html:hidden property="id"/><html:hidden property="versionNo"/>
</td>
</tr>
<tr>
<th size="12" maxlength="10" errorStylesize="26" maxlength="20" errorStylesize="12" maxlength="10" errorStylesize="10" maxlength="8" errorStylesize="12" maxlength="10" errorStyleproperty="id" labelProperty="deptName"/>
</html:select>
</td>
<html:text property="deptId_test" size="12" maxlength="10" onkeydown="SetdefaultData(this.form.elements['deptId_test'],document.getElementById('testID'))" onkeyup="SetdefaultData(this.form.elements['deptId_test'],document.getElementById('testID'))"/>
</tr>
<tr>
<th property="KeyData" labelProperty="ValData"/>
</html:select>
</td>
</tr>
</table>
<html:hidden property="versionNo"/>
</div>
</tiles:put>
</tiles:insert>
</s:form>
</body>
</html>