表单为空时弹出提示,代码怎么写?

来源:百度知道 编辑:UC知道 时间:2024/05/31 21:05:10
建了一个查询网页,但什么也不输入的时候,查出来的是全部数据库中的数据,怎样写代码,可以让表单为空时不查询,而是弹出一个提示?谢谢

<script language="JavaScript">function check()
{
if(document.form1.cn_name.value=="")
{
alert("Please fill in name!");
document.form1.cn_name.focus();
return false;
}</script>
<form name="form1" method="POST" action="<%=Action%>" onSubmit="return check()">
<table>
<tr>
<td>名字:
<input name="cn_name" type="text" id="cn_name">
<input type="submit" name="Submit" value="查询"></td>
</tr>
</table>
</form>

同上