为什么我在form中加了<input type="hidden" name="action" value="post">提交隐藏变量时,就不能引用javascript来进行客户端的是否为空的验证,而不加时就可以验证呢??<%
request.setCharacterEncoding("GBK");
String action = request.getParameter("action");//接收下面的form提交的action
response.sendRedirect("article.jsp");
%>//下面是javascript代码
<script language="JavaScript1.2" type="text/javascript">
<!--
function isEmpty()
{
var title = document.postForm.title.value;
var cont = document.postForm.cont.value;
if(title=="")
{
alert("主题不能为空!!");
return false;
}
if(title!="" && cont!="")
{
alert("提交成功");
return true;
}
}//下面是form中的代码
<form name="postForm" action="post.jsp" method="post">
//post.jsp是本身,就是form表单提交给本身
<input type="hidden" name="action" value="post">
<table align="center" border="1" width="100%">
<tr>
<td class="jive-subject" align="left">
<img src="images/up-10x10.gif">主题内容
</td>
</tr>
<tr>
<td>
<textarea rows="15" cols="150" name="cont"></textarea>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="提交" onClick="isEmpty()"/>//调用isEmpty()
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
request.setCharacterEncoding("GBK");
String action = request.getParameter("action");//接收下面的form提交的action
response.sendRedirect("article.jsp");
%>//下面是javascript代码
<script language="JavaScript1.2" type="text/javascript">
<!--
function isEmpty()
{
var title = document.postForm.title.value;
var cont = document.postForm.cont.value;
if(title=="")
{
alert("主题不能为空!!");
return false;
}
if(title!="" && cont!="")
{
alert("提交成功");
return true;
}
}//下面是form中的代码
<form name="postForm" action="post.jsp" method="post">
//post.jsp是本身,就是form表单提交给本身
<input type="hidden" name="action" value="post">
<table align="center" border="1" width="100%">
<tr>
<td class="jive-subject" align="left">
<img src="images/up-10x10.gif">主题内容
</td>
</tr>
<tr>
<td>
<textarea rows="15" cols="150" name="cont"></textarea>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="提交" onClick="isEmpty()"/>//调用isEmpty()
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
你的 document.postForm.title在哪里
应该写在form的onsubmit事件里
request.setCharacterEncoding("GBK");
String action = request.getParameter("action");//接收下面的form提交的action
response.sendRedirect("article.jsp");
%> //下面是javascript代码
<script language="JavaScript1.2" type="text/javascript">
<!--
function isEmpty()
{
var title = document.postForm.title.value;
var cont = document.postForm.cont.value;
if(title=="")
{
alert("主题不能为空!!");
return false;
}
if(title!="" && cont!="")
{
alert("提交成功");
return true;
}
} //下面是form中的代码
<form name="postForm" action="post.jsp" method="post" onsubmit="return isEmpty()">
//post.jsp是本身,就是form表单提交给本身
<input type="hidden" name="action" value="post">
<table align="center" border="1" width="100%">
<tr>
<td>
<input type="text" name="title"/>
</td>
</tr>
<tr>
<td>
<textarea rows="15" cols="150" name="cont"> </textarea>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="提交" /> //调用isEmpty()
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
我写成这样也不行呀??
怎么回事呀??
request.setCharacterEncoding("GBK");
String action = request.getParameter("action");//接收下面的form提交的action
response.sendRedirect("article.jsp");
%> //下面是javascript代码
<script language="JavaScript1.2" type="text/javascript">
<!--
function isEmpty()
{
var title = document.postForm.title.value;
var cont = document.postForm.cont.value;
if(title=="")
{
alert("主题不能为空!!");
return false;
}
if(title!="" && cont!="")
{
alert("提交成功");
return true;
}
}
//-->
</script>//下面是form中的代码
<form name="postForm" action="post.jsp" method="post" onsubmit="return isEmpty()">
//post.jsp是本身,就是form表单提交给本身
<input type="hidden" name="action" value="post">
<table align="center" border="1" width="100%">
<tr>
<td>
<input type="text" name="title"/>
</td>
</tr>
<tr>
<td>
<textarea rows="15" cols="150" name="cont"> </textarea>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="提交" /> //调用isEmpty()
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>