<%@ page language="java" pageEncoding="GBK"%><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>领养宝贝</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css" href="/epet/calc/styles.css">
<script>
var validateMsg = "";
function checkNotEmpty(ctlName,label)
{
var oCtl = document.forms[0].elements[ctlName];
if (oCtl.value=="")
{
if (label)
{
validateMsg += label;
}
validateMsg += "不能为空!\n";
oCtl.focus();
}
}
function checkValidateMsg()
{
if (validateMsg!="")
{
alert(validateMsg);
return false;
}
return true;
}
function doAdopt()
{
validateMsg = "";
checkNotEmpty("petInfo.petPassword","密码");
checkNotEmpty("petInfo.petOwnerName","宠物主人");
checkNotEmpty("petInfo.petType","类");
checkNotEmpty("petInfo.petName","宠物名");
if (!checkValidateMsg())
{
return;
}
document.forms[0].elements["operate"].value = "doAdopt";
document.forms[0].submit();
}
function setPetType(oSelect)
{
var typeValue = oSelect.options[oSelect.selectedIndex].value;
var oStrength = document.forms[0].elements["petInfo.petStrength"];
var oCute = document.forms[0].elements["petInfo.petCute"];
var oLove = document.forms[0].elements["petInfo.petLove"];
var oPic = document.forms[0].elements["petInfo.petPic"];
var oImg = document.getElementById("petImg");
oPic.value = "/epet/images/pet/";
if (typeValue==1)//Pit
{
oStrength.value = 60;
oCute.value = 60;
oLove.value = 60;
oPic.value += "pig.jpg";
}
else if (typeValue==2)//Cat
{
oStrength.value = 40;
oCute.value = 60;
oLove.value = 80;
oPic.value += "cat.jpg";
}
else if (typeValue==3)//Dragon
{
oStrength.value = 80;
oCute.value = 60;
oLove.value = 40;
oPic.value += "dragon.jpg";
}
else{
oStrength.value = 0;
oCute.value = 0;
oLove.value = 0;
oPic.value += "unkown.jpg";
}
oImg.src = oPic.value;
}
</script> </head>
<body>
<html:form action="pet.do" method="post">
<input type="hidden" name="operate" value="doAdopt">
<input type="hidden" name="petInfo.petPic" value="petImg">
<div class="main_div">
<h1>我的宝贝儿</h1>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="450">
</td>
<td rowspan="2" style="background-color:pink;text-align:right;">
<a href="index.htm">登录</a>
</td>
</tr>
<tr>
<td style="background-color:pink;">
<a href="/epet/index.jsp">首页</a>
|
<a href="/epet/WEB-INF/jsp/pet/adopt.jsp">领养宠物</a>
</td>
</tr>
</table>
</div>
<div class="main_div">
<table>
<tr>
<td width="320px" valign="top">
<table class="input_table" width="100%">
<tr><th>宠物名:</th><td><input type="text" name="petInfo.petName"></td></tr>
<tr><th>类别:</th><td>
<select name="item.petType" onchange="javascript:setPetType(this);"><option value="">请选择...</option>
<option value="1">千禧猪</option>
<option value="2">喵咪</option>
<option value="3">哥斯拉</option></select>
</td></tr>
<tr><th>性别:</th><td>
<input type="radio" name="petInfo.petSex" value="男">男
<input type="radio" name="petInfo.petSex" value="女">女
<input type="radio" name="petInfo.petSex" value="小" checked="checked">小
</td></tr>
<tr><th>力量:</th><td><input type="text" name="petInfo.petStrength" value="" readonly="readonly"></td></tr>
<tr><th>能力:</th><td><input type="text" name="petInfo.petCute" value="" readonly="readonly"></td></tr>
<tr><th>爱心:</th><td><input type="text" name="petInfo.petLove" value="" readonly="readonly"></td></tr>
<tr><th>介绍:</th><td><textarea name="petInfo.petIntro"></textarea></td></tr>
<tr><th>主人名:</th><td><input type="text" name="petInfo.petOwnerName" value=""></td></tr>
<tr><th>宠物EMail:</th><td><input type="text" name="petInfo.petOwnerEmail" value=""></td></tr>
<tr><th>密码:</th><td><input type="password" name="petInfo.petPassword" value=""></td></tr>
<tr><th> </th><td><button onclick="javascript:doAdopt();">领养</button></td></tr>
</table>
</td>
<td valign="top">
<img id="petImg" src="/epet/images/pet/unkown.jpg" />
</td>
</tr>
</table>
</div>
<hr size="1" width="800px" color="black"/>
<div class="main_div" style="border-width:0;text-align:right;">
copyright © 2011 北京阿博泰克北大青鸟信息技术有限公司
</div>
</html:form>
</body>
</html:html>
我提交的时候页面的错误是:
行:24
字符:4
‘value’为空或不是对象。
反正就是提交不了,检查半天也没检查出来,高手帮帮忙啊。
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>领养宝贝</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css" href="/epet/calc/styles.css">
<script>
var validateMsg = "";
function checkNotEmpty(ctlName,label)
{
var oCtl = document.forms[0].elements[ctlName];
if (oCtl.value=="")
{
if (label)
{
validateMsg += label;
}
validateMsg += "不能为空!\n";
oCtl.focus();
}
}
function checkValidateMsg()
{
if (validateMsg!="")
{
alert(validateMsg);
return false;
}
return true;
}
function doAdopt()
{
validateMsg = "";
checkNotEmpty("petInfo.petPassword","密码");
checkNotEmpty("petInfo.petOwnerName","宠物主人");
checkNotEmpty("petInfo.petType","类");
checkNotEmpty("petInfo.petName","宠物名");
if (!checkValidateMsg())
{
return;
}
document.forms[0].elements["operate"].value = "doAdopt";
document.forms[0].submit();
}
function setPetType(oSelect)
{
var typeValue = oSelect.options[oSelect.selectedIndex].value;
var oStrength = document.forms[0].elements["petInfo.petStrength"];
var oCute = document.forms[0].elements["petInfo.petCute"];
var oLove = document.forms[0].elements["petInfo.petLove"];
var oPic = document.forms[0].elements["petInfo.petPic"];
var oImg = document.getElementById("petImg");
oPic.value = "/epet/images/pet/";
if (typeValue==1)//Pit
{
oStrength.value = 60;
oCute.value = 60;
oLove.value = 60;
oPic.value += "pig.jpg";
}
else if (typeValue==2)//Cat
{
oStrength.value = 40;
oCute.value = 60;
oLove.value = 80;
oPic.value += "cat.jpg";
}
else if (typeValue==3)//Dragon
{
oStrength.value = 80;
oCute.value = 60;
oLove.value = 40;
oPic.value += "dragon.jpg";
}
else{
oStrength.value = 0;
oCute.value = 0;
oLove.value = 0;
oPic.value += "unkown.jpg";
}
oImg.src = oPic.value;
}
</script> </head>
<body>
<html:form action="pet.do" method="post">
<input type="hidden" name="operate" value="doAdopt">
<input type="hidden" name="petInfo.petPic" value="petImg">
<div class="main_div">
<h1>我的宝贝儿</h1>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="450">
</td>
<td rowspan="2" style="background-color:pink;text-align:right;">
<a href="index.htm">登录</a>
</td>
</tr>
<tr>
<td style="background-color:pink;">
<a href="/epet/index.jsp">首页</a>
|
<a href="/epet/WEB-INF/jsp/pet/adopt.jsp">领养宠物</a>
</td>
</tr>
</table>
</div>
<div class="main_div">
<table>
<tr>
<td width="320px" valign="top">
<table class="input_table" width="100%">
<tr><th>宠物名:</th><td><input type="text" name="petInfo.petName"></td></tr>
<tr><th>类别:</th><td>
<select name="item.petType" onchange="javascript:setPetType(this);"><option value="">请选择...</option>
<option value="1">千禧猪</option>
<option value="2">喵咪</option>
<option value="3">哥斯拉</option></select>
</td></tr>
<tr><th>性别:</th><td>
<input type="radio" name="petInfo.petSex" value="男">男
<input type="radio" name="petInfo.petSex" value="女">女
<input type="radio" name="petInfo.petSex" value="小" checked="checked">小
</td></tr>
<tr><th>力量:</th><td><input type="text" name="petInfo.petStrength" value="" readonly="readonly"></td></tr>
<tr><th>能力:</th><td><input type="text" name="petInfo.petCute" value="" readonly="readonly"></td></tr>
<tr><th>爱心:</th><td><input type="text" name="petInfo.petLove" value="" readonly="readonly"></td></tr>
<tr><th>介绍:</th><td><textarea name="petInfo.petIntro"></textarea></td></tr>
<tr><th>主人名:</th><td><input type="text" name="petInfo.petOwnerName" value=""></td></tr>
<tr><th>宠物EMail:</th><td><input type="text" name="petInfo.petOwnerEmail" value=""></td></tr>
<tr><th>密码:</th><td><input type="password" name="petInfo.petPassword" value=""></td></tr>
<tr><th> </th><td><button onclick="javascript:doAdopt();">领养</button></td></tr>
</table>
</td>
<td valign="top">
<img id="petImg" src="/epet/images/pet/unkown.jpg" />
</td>
</tr>
</table>
</div>
<hr size="1" width="800px" color="black"/>
<div class="main_div" style="border-width:0;text-align:right;">
copyright © 2011 北京阿博泰克北大青鸟信息技术有限公司
</div>
</html:form>
</body>
</html:html>
我提交的时候页面的错误是:
行:24
字符:4
‘value’为空或不是对象。
反正就是提交不了,检查半天也没检查出来,高手帮帮忙啊。
var oCute = document.forms[0].elements["petInfo.petCute"];
var oLove = document.forms[0].elements["petInfo.petLove"];
var oPic = document.forms[0].elements["petInfo.petPic"];
你这个下面都没填。。它怎么能得到值呢? 当然为空了选择类别之后就出错
{
validateMsg = "";
checkNotEmpty("petInfo.petPassword","密码");
checkNotEmpty("petInfo.petOwnerName","宠物主人");
checkNotEmpty("petInfo.petType","类");
checkNotEmpty("petInfo.petName","宠物名");
if (!checkValidateMsg())
{
return;
}
document.forms[0].elements["operate"].value = "doAdopt";
document.forms[0].submit();
}
这里传的参数咯!