如何将表单内容设置为必填
<tablewidth="500"border="0"align="center"cellpadding="4"cellspacing="1"bgcolor="#CCCC...
<table width="500" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form name="form" method="post" action="<%=indexfilename%>">
<tr bgcolor="#f9f9f9">
<td width="13%" height="20" > <div align="right">姓名:</div></td>
<td width="53%" height="20"> <input type="text" name="name" class="write" size="20" maxLength=8>
*8个字内</td>
<script>
function showimage(){document.images.showimages.src="<%=imdeximg%>"+document.form.sex.options[document.form.sex.selectedIndex].value+""+document.form.img.options[document.form.img.selectedIndex].value+".gif";}
</script>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right"> 性别: </td>
<td height="20"> <select name="sex" size="1" onChange="showimage()">
<option value="1">男</option>
<option value="0">女</option>
</select> </td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">QQ:</td>
<td height="20"> <input name="qq" type="text" id="qq" size="35" maxLength=15 class="write">
*</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">主页: </td>
<td height="20"> <input name="web" type="text" value="http://" size="35" maxLength=50 class="write">
</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">来自:</td>
<td height="20"> <input name="come" type="text" id="come" size="35" class="write"></td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">电子邮箱:</td>
<td height="20"><input name="email" type="text" value="" size="35" maxlength=50 class="write">
*</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">主题:</td>
<td height="20">
<input name="title" type="text" class="write" id="title" size="35" maxLength=10>
*
</td>
</tr>
<tr bgcolor="#f9f9f9">
<td align="right" valign="top"> 留言内容: </td>
<td> <textarea name="words" cols="50" rows="8" class="input1" id="words"
onKeyDown=gbcount(this.form.words,this.form.total,this.form.used,this.form.remain);
onKeyUp=gbcount(this.form.words,this.form.total,this.form.used,this.form.remain);></textarea>
* </td>
</tr>
<tr bgcolor="#f9f9f9">
<td align="right" valign="top" height="30"> </td>
<td height="30">最多字数: <INPUT disabled maxLength=4 name=total size=3 value=<%=txt%>>
已用字数:
<INPUT disabled maxLength=4 name=used size=3 value=0>
剩余字数:
<INPUT disabled maxLength=4 name=remain size=3 value=<%=txt%>></td>
</tr>
<tr align="center" bgcolor="#EAEAEA">
<td height="20" colspan="2"> <input name='validatecode' type='text' size='5'> <img
src='/validatecode.asp' align='absmiddle' border='0'><br>
<br>
<input type="hidden" name="action_e" value="Add_New">
<input type="submit" name="Submit" value=" 提 交 " class="input1"> <input type="reset" name="Submit2" value=" 重 写 " class="input1">
</td></tr>
</form>
</table>
这是我公司网站留言板的表单,我想让带星号的为必填,并且如何防止站外提交,我的站每天有几百条垃圾留言,请高手帮忙,
希望高手说的详细些,如果能解决问题,我将再加50分 展开
<form name="form" method="post" action="<%=indexfilename%>">
<tr bgcolor="#f9f9f9">
<td width="13%" height="20" > <div align="right">姓名:</div></td>
<td width="53%" height="20"> <input type="text" name="name" class="write" size="20" maxLength=8>
*8个字内</td>
<script>
function showimage(){document.images.showimages.src="<%=imdeximg%>"+document.form.sex.options[document.form.sex.selectedIndex].value+""+document.form.img.options[document.form.img.selectedIndex].value+".gif";}
</script>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right"> 性别: </td>
<td height="20"> <select name="sex" size="1" onChange="showimage()">
<option value="1">男</option>
<option value="0">女</option>
</select> </td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">QQ:</td>
<td height="20"> <input name="qq" type="text" id="qq" size="35" maxLength=15 class="write">
*</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">主页: </td>
<td height="20"> <input name="web" type="text" value="http://" size="35" maxLength=50 class="write">
</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">来自:</td>
<td height="20"> <input name="come" type="text" id="come" size="35" class="write"></td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">电子邮箱:</td>
<td height="20"><input name="email" type="text" value="" size="35" maxlength=50 class="write">
*</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">主题:</td>
<td height="20">
<input name="title" type="text" class="write" id="title" size="35" maxLength=10>
*
</td>
</tr>
<tr bgcolor="#f9f9f9">
<td align="right" valign="top"> 留言内容: </td>
<td> <textarea name="words" cols="50" rows="8" class="input1" id="words"
onKeyDown=gbcount(this.form.words,this.form.total,this.form.used,this.form.remain);
onKeyUp=gbcount(this.form.words,this.form.total,this.form.used,this.form.remain);></textarea>
* </td>
</tr>
<tr bgcolor="#f9f9f9">
<td align="right" valign="top" height="30"> </td>
<td height="30">最多字数: <INPUT disabled maxLength=4 name=total size=3 value=<%=txt%>>
已用字数:
<INPUT disabled maxLength=4 name=used size=3 value=0>
剩余字数:
<INPUT disabled maxLength=4 name=remain size=3 value=<%=txt%>></td>
</tr>
<tr align="center" bgcolor="#EAEAEA">
<td height="20" colspan="2"> <input name='validatecode' type='text' size='5'> <img
src='/validatecode.asp' align='absmiddle' border='0'><br>
<br>
<input type="hidden" name="action_e" value="Add_New">
<input type="submit" name="Submit" value=" 提 交 " class="input1"> <input type="reset" name="Submit2" value=" 重 写 " class="input1">
</td></tr>
</form>
</table>
这是我公司网站留言板的表单,我想让带星号的为必填,并且如何防止站外提交,我的站每天有几百条垃圾留言,请高手帮忙,
希望高手说的详细些,如果能解决问题,我将再加50分 展开
4个回答
展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<table width="500" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form name="form" method="post" >
<tr bgcolor="#f9f9f9">
<td width="13%" height="20" > <div align="right">姓名:</div></td>
<td width="53%" height="20"> <input type="text" name="name" id="name" class="write" size="20" maxLength=8>
*8个字内</td>
<script>
function showimage(){document.images.showimages.src="<%=imdeximg%>"+document.form.sex.options[document.form.sex.selectedIndex].value+""+document.form.img.options[document.form.img.selectedIndex].value+".gif";}
</script>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right"> 性别: </td>
<td height="20"> <select name="sex" size="1" onChange="showimage()">
<option value="1">男</option>
<option value="0">女</option>
</select> </td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">QQ:</td>
<td height="20"> <input name="qq" type="text" id="qq" size="35" maxLength=15 class="write">
*</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">主页: </td>
<td height="20"> <input name="web" type="text" value="http://" size="35" maxLength=50 class="write">
</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">来自:</td>
<td height="20"> <input name="come" type="text" id="come" size="35" class="write"></td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">电子邮箱:</td>
<td height="20"><input name="email" type="text" value="" size="35" maxlength=50 class="write">
*</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">主题:</td>
<td height="20">
<input name="title" type="text" class="write" id="title" size="35" maxLength=10>
*
</td>
</tr>
<tr bgcolor="#f9f9f9">
<td align="right" valign="top"> 留言内容: </td>
<td> <textarea name="words" cols="50" rows="8" class="input1" id="words"
onKeyDown=gbcount(this.form.words,this.form.total,this.form.used,this.form.remain);
onKeyUp=gbcount(this.form.words,this.form.total,this.form.used,this.form.remain);></textarea>
* </td>
</tr>
<tr bgcolor="#f9f9f9">
<td align="right" valign="top" height="30"> </td>
<td height="30">最多字数: <INPUT disabled maxLength=4 name=total size=3 value=<%=txt%>>
已用字数:
<INPUT disabled maxLength=4 name=used size=3 value=0>
剩余字数:
<INPUT disabled maxLength=4 name=remain size=3 value=<%=txt%>></td>
</tr>
<tr align="center" bgcolor="#EAEAEA">
<td height="20" colspan="2"> <input name='validatecode' type='text' size='5'> <img
src='/validatecode.asp' align='absmiddle' border='0'><br>
<br>
<input type="hidden" name="action_e" value="Add_New">
<input type="button" onclick="DoSave();" name="Submit" value=" 提 交 " class="input1"> <input type="reset" name="Submit2" value=" 重 写 " class="input1">
</td></tr>
</form>
</table>
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkForm(){
var name = document.getElementById('name');
if(name.value == ''){
alert("姓名不能为空");
return false;
}
return true;
}
function DoSave(){
if(checkForm()){
document.form.action = "<%=indexfilename%>";
document.form.submit();
}
}
//-->
</SCRIPT>
</BODY>
</HTML>
给你写了一个,就是姓名不能空,如果其它的也要做这个判断的话,你再把其它的都加上,如果不清楚,用百度hi我
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<table width="500" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form name="form" method="post" >
<tr bgcolor="#f9f9f9">
<td width="13%" height="20" > <div align="right">姓名:</div></td>
<td width="53%" height="20"> <input type="text" name="name" id="name" class="write" size="20" maxLength=8>
*8个字内</td>
<script>
function showimage(){document.images.showimages.src="<%=imdeximg%>"+document.form.sex.options[document.form.sex.selectedIndex].value+""+document.form.img.options[document.form.img.selectedIndex].value+".gif";}
</script>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right"> 性别: </td>
<td height="20"> <select name="sex" size="1" onChange="showimage()">
<option value="1">男</option>
<option value="0">女</option>
</select> </td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">QQ:</td>
<td height="20"> <input name="qq" type="text" id="qq" size="35" maxLength=15 class="write">
*</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">主页: </td>
<td height="20"> <input name="web" type="text" value="http://" size="35" maxLength=50 class="write">
</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">来自:</td>
<td height="20"> <input name="come" type="text" id="come" size="35" class="write"></td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">电子邮箱:</td>
<td height="20"><input name="email" type="text" value="" size="35" maxlength=50 class="write">
*</td>
</tr>
<tr bgcolor="#f9f9f9">
<td height="20" align="right">主题:</td>
<td height="20">
<input name="title" type="text" class="write" id="title" size="35" maxLength=10>
*
</td>
</tr>
<tr bgcolor="#f9f9f9">
<td align="right" valign="top"> 留言内容: </td>
<td> <textarea name="words" cols="50" rows="8" class="input1" id="words"
onKeyDown=gbcount(this.form.words,this.form.total,this.form.used,this.form.remain);
onKeyUp=gbcount(this.form.words,this.form.total,this.form.used,this.form.remain);></textarea>
* </td>
</tr>
<tr bgcolor="#f9f9f9">
<td align="right" valign="top" height="30"> </td>
<td height="30">最多字数: <INPUT disabled maxLength=4 name=total size=3 value=<%=txt%>>
已用字数:
<INPUT disabled maxLength=4 name=used size=3 value=0>
剩余字数:
<INPUT disabled maxLength=4 name=remain size=3 value=<%=txt%>></td>
</tr>
<tr align="center" bgcolor="#EAEAEA">
<td height="20" colspan="2"> <input name='validatecode' type='text' size='5'> <img
src='/validatecode.asp' align='absmiddle' border='0'><br>
<br>
<input type="hidden" name="action_e" value="Add_New">
<input type="button" onclick="DoSave();" name="Submit" value=" 提 交 " class="input1"> <input type="reset" name="Submit2" value=" 重 写 " class="input1">
</td></tr>
</form>
</table>
<SCRIPT LANGUAGE="JavaScript">
<!--
function checkForm(){
var name = document.getElementById('name');
if(name.value == ''){
alert("姓名不能为空");
return false;
}
return true;
}
function DoSave(){
if(checkForm()){
document.form.action = "<%=indexfilename%>";
document.form.submit();
}
}
//-->
</SCRIPT>
</BODY>
</HTML>
给你写了一个,就是姓名不能空,如果其它的也要做这个判断的话,你再把其它的都加上,如果不清楚,用百度hi我
展开全部
function check(){
if(document.getElementById("remain ").value=="")
{
alert("主页不容许为空");
return false;
}
return true;
}
以上是js代码
<form name="form" method="post" action="<%=indexfilename%>" onsubmit="return check()">
if(document.getElementById("remain ").value=="")
{
alert("主页不容许为空");
return false;
}
return true;
}
以上是js代码
<form name="form" method="post" action="<%=indexfilename%>" onsubmit="return check()">
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
http://www.520hack.com/Article/Text4/200807/10753.html
这里就是一个跨站提交的列子
至于带星号的必填 用js脚本写就是了
如 document.getElementById("remain ").value
再根据他的值来判断为不为空
为空的话看你自己怎么去处理了
并将其保存在js文件中
这里就是一个跨站提交的列子
至于带星号的必填 用js脚本写就是了
如 document.getElementById("remain ").value
再根据他的值来判断为不为空
为空的话看你自己怎么去处理了
并将其保存在js文件中
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
做判断,必填项如果为空,则不允许提交即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |