您的位置:首页 > 其它

动态设置select与radio的默认值

2011-10-07 23:29 447 查看
<%@ page language="java" import="java.util.*,isa.model.PersonBean" contentType="text/html;charset=gb2312" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'personmu.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

<script   language= JavaScript>

function   check()
{
var id=document.form1.id.value;
var name=document.form1.name.value;
if(id==""){
alert("对不起,会员号不能为空");
return false;
}else if(name==""){
alert("对不起,姓名不能为空");
return false;
}
else
{
return true;
}
}
function initradio(rName,rValue){
var rObj = document.getElementsByName(rName);

for(var i = 0;i < rObj.length;i++){
if(rObj[i].value == rValue){
rObj[i].checked =  'checked';
}
}
}
</script>
</head>

<body bgcolor="#ccffff">
<%
//防止用户非法登录
String u=(String)session.getAttribute("id");
String l=(String)session.getAttribute("level");
if(u==null){
response.sendRedirect("login.jsp?err=1");
return;
}
//要显示的信息从Request中取
PersonBean pb=(PersonBean)request.getAttribute("result");
%>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0" height="250px">
<tr>
<td scope="row" width="450">
<form id="form1" name="form1" onsubmit="return check()" method="post" action="PersonMUServlet">
<table width="400" align="center" >
<tr>
<td height="30" colspan="2"><div align="center">会   员   管   理</div></td>
</tr>
<tr>
<td width="150" height="30" align="right">刚果号:</td>
<td width="250" align="left">
<input type="text" name="id" value="<%=pb.getpId() %>" readonly="readonly" maxlength="16" size="24"/>
</td>
</tr>
<tr>
<td width="150" height="30" align="right">姓  名:</td>
<td width="250" align="left">
<input type="text" name="name" value="<%=pb.getpName() %>" maxlength="16" size="24"/>
</td>
</tr>
<tr>
<td width="150" height="30" align="right">部  门:</td>
<td width="250" align="left">
<input type="text" name="dept" readonly="readonly" value="<%=pb.getdNo() %>" maxlength="16" size="24"/>
</td>
</tr>

<tr>
<td width="150" height="30" align="right"> 小  组:</td>
<td width="250" align="left">
<input type="text" name="team" readonly="readonly" value="<%=pb.gettNo() %>" maxlength="16" size="24"/>
</td>
</tr>
<tr>
<td width="150" height="30" align="right">职  务:</td>
<td width="250" align="left">
<select name="job" size="1" >
<option value="普通会员">普通会员</option>
<option value="副组长">副组长</option>
<option value="组长">组长</option>
<option value="主任">主任</option>
<option value="副部长">副部长</option>
<option value="部长">部长</option>
<option value="秘书长">秘书长</option>
<option value="副会长">副会长</option>
<option value="会长">会长</option>
</select>
<!-- 动态设置Select的默认值 -->
<script language= JavaScript>
var job= "<%=pb.getJob()  %>";
document.getElementsByName("job")[0].value=job;
</script>
</td>
</tr>
<tr>
<td width="150" height="30" align="right">专  业:</td>
<td width="250" align="left">
<input type="text" name="speciality" value="<%=pb.getSpeciality() %>" size="24" maxlength="24"/>
</td>
</tr>
<tr>
<td width="150" height="30" align="right">性  别:</td>
<td width="250" align="left">
<input name="sex" type="radio" value="男" checked="checked" />男
<input type="radio" name="sex" value="女" />女
<!-- 动态设置radio的默认值 -->
<script language= JavaScript>
var s="<%=pb.getSex() %>";
initradio('sex',s);
</script>
</td>
</tr>
<tr>
<td width="150" height="30" align="right">电  话:</td>
<td width="250" align="left">
<input type="text" name="tel" value="<%=pb.getTel() %>" maxlength="15" size="24"/>
</td>
</tr>
<tr>
<td colspan="2" width="400" height="30" align="center">
<input type="submit" name="submit" value="提交" />
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: