ASP表单设置必填项的问题
<tablecellspacing="0"cellpadding="9"width="600"align="center"border="0"><tbody><tr><t...
<table cellspacing="0" cellpadding="9" width="600" align="center"
border="0">
<tbody>
<tr>
<td align="middle"><table class="border_pink" cellspacing="1" cellpadding="5" width="100%"
bgcolor="#e3017e" border="0">
<tbody>
<tr>
<td class="title" align="left" bgcolor="#f7d1e8">联络方式(不公开):</td>
</tr>
<tr>
<td align="middle" bgcolor="#ffffff"><table cellspacing="5" cellpadding="0" width="560" border="0">
<tbody>
<tr align="left">
<td width="75"><span class="STYLE1">*</span>联系电话1</td>
<td width="199"><input maxlength="15" name="PHONE1" />
</td>
<td width="72">联系电话2</td>
<td width="189"><input maxlength="15" name="PHONE2" /></td>
</tr>
<tr align="left">
<td> </td>
<td colspan="3">提醒:别忘记了输入区号,例如010-88888888</td>
</tr>
<tr align="left">
<td width="75">QQ 号码</td>
<td width="199"><input maxlength="14" name="QQ_NUM" />
</td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>住 址</td>
<td colspan="3"><input maxlength="50" size="60" name="ADDRESS" />
</td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>紧急联系人</td>
<td><input maxlength="10" name="CONNECTPERSON" /></td>
<td><span class="STYLE1">*</span>与您的关系</td>
<td><input maxlength="10" name="RELATION" /></td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>联系电话</td>
<td><input maxlength="15" name="PERSONPHONE" /></td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
一个ASP报名的表单
怎么设置每一个表单都是必填
希望达人可以帮助下
所有积分放松
谢谢
万分感谢 展开
border="0">
<tbody>
<tr>
<td align="middle"><table class="border_pink" cellspacing="1" cellpadding="5" width="100%"
bgcolor="#e3017e" border="0">
<tbody>
<tr>
<td class="title" align="left" bgcolor="#f7d1e8">联络方式(不公开):</td>
</tr>
<tr>
<td align="middle" bgcolor="#ffffff"><table cellspacing="5" cellpadding="0" width="560" border="0">
<tbody>
<tr align="left">
<td width="75"><span class="STYLE1">*</span>联系电话1</td>
<td width="199"><input maxlength="15" name="PHONE1" />
</td>
<td width="72">联系电话2</td>
<td width="189"><input maxlength="15" name="PHONE2" /></td>
</tr>
<tr align="left">
<td> </td>
<td colspan="3">提醒:别忘记了输入区号,例如010-88888888</td>
</tr>
<tr align="left">
<td width="75">QQ 号码</td>
<td width="199"><input maxlength="14" name="QQ_NUM" />
</td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>住 址</td>
<td colspan="3"><input maxlength="50" size="60" name="ADDRESS" />
</td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>紧急联系人</td>
<td><input maxlength="10" name="CONNECTPERSON" /></td>
<td><span class="STYLE1">*</span>与您的关系</td>
<td><input maxlength="10" name="RELATION" /></td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>联系电话</td>
<td><input maxlength="15" name="PERSONPHONE" /></td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
一个ASP报名的表单
怎么设置每一个表单都是必填
希望达人可以帮助下
所有积分放松
谢谢
万分感谢 展开
展开全部
我来抢个沙发,助人为乐嘛:给你写了2个验证的函数:
<script language="javascript">
<!--
function Check()
{
if (form1.PHONE1.value=="")
{
alert("请输入联系电话1")
document.form1.PHONE1.focus();
return false
}
if (form1.PHONE2.value=="")
{
alert("请输入联系电话2");
document.form1.PHONE2.focus();
return false
}
var num = document.form1.QQ_NUM.value;
if (num!=""&&!num.match(/^(\d)+$/))
{
alert ("请输入QQ 号码,而且QQ只能是数字!")
return false;
}
if (form1.ADDRESS.value=="")
{
alert("请输入到住 址");
document.form1.ADDRESS.focus();
return false
}
if (form1.CONNECTPERSON.value=="")
{
alert("紧急联系人")
document.form1.CONNECTPERSON.focus();
return false
}
if (form1.RELATION.value=="")
{
alert("与您的关系");
document.form1.RELATION.focus();
return false
}
if (form1.PERSONPHONE.value=="")
{
alert("联系电话")
document.form1.PERSONPHONE.focus();
return false
}
return true
}
//-->
</script>
<!--------------------用法:将以上代码拷贝到</head>之前,在你的表单里民加句<Form onSubmit="retrun Check();">---------------------->
下面还要在提交表单的时候做ASP验证:
<%
'错误提示代码
Sub Alert(Msg)
Response.Write("<script>alert('"& Msg &"');history.go(-1);</script>")
Response.End()
End Sub
'定义变量
Dim PHONE1,PHONE2,QQ_NUM,ADDRESS,CONNECTPERSON,RELATION,PERSONPHONE
PHONE1=Trim(Request.Form("PHONE1"))
PHONE2=Trim(Request.Form("PHONE2"))
QQ_NUM=Trim(Request.Form("QQ_NUM"))
ADDRESS=Trim(Request.Form("ADDRESS"))
CONNECTPERSON=Trim(Request.Form("CONNECTPERSON"))
RELATION=Trim(Request.Form("RELATION"))
PERSONPHONE=Trim(Request.Form("PERSONPHONE"))
'对变量进行判断是否为空,下面的
If PHONE1 = "" Then
Alert "对不起,联系电话1不能为空!"
FoundErr =True
End If
If PHONE2 = "" Then
Alert "对不起,联系电话2不能为空!"
FoundErr=True
End If
If IsNumeric(QQ_NUM)=False Then
Alert "对不起,QQ号码不能为空而且只能为数字!"
FoundErr = True
End If
If ADDRESS = "" Then
Alert "对不起,联系地址不能为空!"
FoundErr = True
End If
If CONNECTPERSON = "" Then
Alert "对不起,紧急联系人不能为空!"
FoundErr = True
End If
If RELATION= "" Then
Alert "对不起,与您的关系不能为空!"
FoundEr r= True
End If
If PERSONPHONE = "" Then
Alert "对不起,联系电话不能为空!"
FoundErr = True
End If
'在对表单判断完后现在就可以写入数据库了
If FoundErr <> True Then
Set Rs=SerVer.CreateObject("Adodb.recordset")
SQL="Select * From xxx "
Rs.open SQL,conn,1,3
Rs.addnew()
rs("PHONE1")=PHONE1
rs("PHONE2")=PHONE2
rs("QQ_NUM")=QQ_NUM
rs("ADDRESS")=ADDRESS
'.....略
%>
<script language="javascript">
<!--
function Check()
{
if (form1.PHONE1.value=="")
{
alert("请输入联系电话1")
document.form1.PHONE1.focus();
return false
}
if (form1.PHONE2.value=="")
{
alert("请输入联系电话2");
document.form1.PHONE2.focus();
return false
}
var num = document.form1.QQ_NUM.value;
if (num!=""&&!num.match(/^(\d)+$/))
{
alert ("请输入QQ 号码,而且QQ只能是数字!")
return false;
}
if (form1.ADDRESS.value=="")
{
alert("请输入到住 址");
document.form1.ADDRESS.focus();
return false
}
if (form1.CONNECTPERSON.value=="")
{
alert("紧急联系人")
document.form1.CONNECTPERSON.focus();
return false
}
if (form1.RELATION.value=="")
{
alert("与您的关系");
document.form1.RELATION.focus();
return false
}
if (form1.PERSONPHONE.value=="")
{
alert("联系电话")
document.form1.PERSONPHONE.focus();
return false
}
return true
}
//-->
</script>
<!--------------------用法:将以上代码拷贝到</head>之前,在你的表单里民加句<Form onSubmit="retrun Check();">---------------------->
下面还要在提交表单的时候做ASP验证:
<%
'错误提示代码
Sub Alert(Msg)
Response.Write("<script>alert('"& Msg &"');history.go(-1);</script>")
Response.End()
End Sub
'定义变量
Dim PHONE1,PHONE2,QQ_NUM,ADDRESS,CONNECTPERSON,RELATION,PERSONPHONE
PHONE1=Trim(Request.Form("PHONE1"))
PHONE2=Trim(Request.Form("PHONE2"))
QQ_NUM=Trim(Request.Form("QQ_NUM"))
ADDRESS=Trim(Request.Form("ADDRESS"))
CONNECTPERSON=Trim(Request.Form("CONNECTPERSON"))
RELATION=Trim(Request.Form("RELATION"))
PERSONPHONE=Trim(Request.Form("PERSONPHONE"))
'对变量进行判断是否为空,下面的
If PHONE1 = "" Then
Alert "对不起,联系电话1不能为空!"
FoundErr =True
End If
If PHONE2 = "" Then
Alert "对不起,联系电话2不能为空!"
FoundErr=True
End If
If IsNumeric(QQ_NUM)=False Then
Alert "对不起,QQ号码不能为空而且只能为数字!"
FoundErr = True
End If
If ADDRESS = "" Then
Alert "对不起,联系地址不能为空!"
FoundErr = True
End If
If CONNECTPERSON = "" Then
Alert "对不起,紧急联系人不能为空!"
FoundErr = True
End If
If RELATION= "" Then
Alert "对不起,与您的关系不能为空!"
FoundEr r= True
End If
If PERSONPHONE = "" Then
Alert "对不起,联系电话不能为空!"
FoundErr = True
End If
'在对表单判断完后现在就可以写入数据库了
If FoundErr <> True Then
Set Rs=SerVer.CreateObject("Adodb.recordset")
SQL="Select * From xxx "
Rs.open SQL,conn,1,3
Rs.addnew()
rs("PHONE1")=PHONE1
rs("PHONE2")=PHONE2
rs("QQ_NUM")=QQ_NUM
rs("ADDRESS")=ADDRESS
'.....略
%>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
for (i=1; i<a.length;i=i+4){
if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
v=o.value;t=a[i+2];
if (o.type=='text'||o.type=='password'||o.type=='hidden'){
if (r&&v.length==0){err=true}
if (v.length>0)
if (t==1){ //fromto
ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
} else if (t==2){
rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
} else if (t==3){ // date
ma=a[i+1].split("#");at=v.match(ma[0]);
if(at){
cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
dte=new Date(cy,cm,cd);
if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
}else{err=true}
} else if (t==4){ // time
ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
} else if (t==5){ // check this 2
if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
if(!o1.checked){err=true}
} else if (t==6){ // the same
if(v!=MM_findObj(a[i+1]).value){err=true}
}
} else
if (!o.type&&o.length>0&&o[0].type=='radio'){
at = a[i].match(/(.*)\[(\d+)\].*/i);
o2=(o.length>1)?o[at[2]]:o;
if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
if (t==2){
oo=false;
for(j=0;j<o.length;j++){oo=oo||o[j].checked}
if(!oo){s+='* '+a[i+3]+'\n'}
}
} else if (o.type=='checkbox'){
if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
} else if (o.type=='select-one'||o.type=='select-multiple'){
if(t==1&&o.selectedIndex/1==0){err=true}
}else if (o.type=='textarea'){
if(v.length<a[i+1]){err=true}
}
if (err){s+='* '+a[i+3]+'\n'; err=false}
}
if (s!=''){alert('收藏温馨提示:\t\t\t\t\t\n\n'+s)}
document.MM_returnValue = (s=='');
}
//-->
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table cellspacing="0" cellpadding="9" width="600" align="center"
border="0">
<tbody>
<tr>
<td align="middle"><table class="border_pink" cellspacing="1" cellpadding="5" width="100%"
bgcolor="#e3017e" border="0">
<tbody>
<tr>
<td class="title" align="left" bgcolor="#f7d1e8">联络方式(不公开):</td>
</tr>
<tr>
<td align="middle" bgcolor="#ffffff"><table cellspacing="5" cellpadding="0" width="560" border="0">
<tbody>
<tr align="left">
<td width="75"><span class="STYLE1">*</span>联系电话1</td>
<td width="199"><input maxlength="15" name="PHONE1" />
</td>
<td width="72">联系电话2</td>
<td width="189"><input maxlength="15" name="PHONE2" /></td>
</tr>
<tr align="left">
<td> </td>
<td colspan="3">提醒:别忘记了输入区号,例如010-88888888</td>
</tr>
<tr align="left">
<td width="75">QQ 号码</td>
<td width="199"><input maxlength="14" name="QQ_NUM" />
</td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>住 址</td>
<td colspan="3"><input maxlength="50" size="60" name="ADDRESS" />
</td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>紧急联系人</td>
<td><input maxlength="10" name="CONNECTPERSON" /></td>
<td><span class="STYLE1">*</span>与您的关系</td>
<td><input maxlength="10" name="RELATION" /></td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>联系电话</td>
<td><input maxlength="15" name="PERSONPHONE" /></td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
<label>
<input name="Submit" type="submit" onclick="YY_checkform('form1','PHONE1','#q','1','Field \'PHONE1\' 必须填写','PHONE2','#q','1','Field \'PHONE2\' 必须填写','QQ_NUM','#q','1','Field \'QQ_NUM\' 必须填写','ADDRESS','#q','1','Field \'ADDRESS\' 必须填写','CONNECTPERSON','#q','1','Field \'CONNECTPERSON\' 必须填写','RELATION','#q','1','Field \'RELATION\' 必须填写','PERSONPHONE','#q','1','Field \'PERSONPHONE\' 必须填写');return document.MM_returnValue" value="提交" />
</label>
</form>
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function YY_checkform() { //v4.71
//copyright (c)1998,2002 Yaromat.com
var a=YY_checkform.arguments,oo=true,v='',s='',err=false,r,o,at,o1,t,i,j,ma,rx,cd,cm,cy,dte,at;
for (i=1; i<a.length;i=i+4){
if (a[i+1].charAt(0)=='#'){r=true; a[i+1]=a[i+1].substring(1);}else{r=false}
o=MM_findObj(a[i].replace(/\[\d+\]/ig,""));
o1=MM_findObj(a[i+1].replace(/\[\d+\]/ig,""));
v=o.value;t=a[i+2];
if (o.type=='text'||o.type=='password'||o.type=='hidden'){
if (r&&v.length==0){err=true}
if (v.length>0)
if (t==1){ //fromto
ma=a[i+1].split('_');if(isNaN(v)||v<ma[0]/1||v > ma[1]/1){err=true}
} else if (t==2){
rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-zA-Z]{2,4}$");if(!rx.test(v))err=true;
} else if (t==3){ // date
ma=a[i+1].split("#");at=v.match(ma[0]);
if(at){
cd=(at[ma[1]])?at[ma[1]]:1;cm=at[ma[2]]-1;cy=at[ma[3]];
dte=new Date(cy,cm,cd);
if(dte.getFullYear()!=cy||dte.getDate()!=cd||dte.getMonth()!=cm){err=true};
}else{err=true}
} else if (t==4){ // time
ma=a[i+1].split("#");at=v.match(ma[0]);if(!at){err=true}
} else if (t==5){ // check this 2
if(o1.length)o1=o1[a[i+1].replace(/(.*\[)|(\].*)/ig,"")];
if(!o1.checked){err=true}
} else if (t==6){ // the same
if(v!=MM_findObj(a[i+1]).value){err=true}
}
} else
if (!o.type&&o.length>0&&o[0].type=='radio'){
at = a[i].match(/(.*)\[(\d+)\].*/i);
o2=(o.length>1)?o[at[2]]:o;
if (t==1&&o2&&o2.checked&&o1&&o1.value.length/1==0){err=true}
if (t==2){
oo=false;
for(j=0;j<o.length;j++){oo=oo||o[j].checked}
if(!oo){s+='* '+a[i+3]+'\n'}
}
} else if (o.type=='checkbox'){
if((t==1&&o.checked==false)||(t==2&&o.checked&&o1&&o1.value.length/1==0)){err=true}
} else if (o.type=='select-one'||o.type=='select-multiple'){
if(t==1&&o.selectedIndex/1==0){err=true}
}else if (o.type=='textarea'){
if(v.length<a[i+1]){err=true}
}
if (err){s+='* '+a[i+3]+'\n'; err=false}
}
if (s!=''){alert('收藏温馨提示:\t\t\t\t\t\n\n'+s)}
document.MM_returnValue = (s=='');
}
//-->
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table cellspacing="0" cellpadding="9" width="600" align="center"
border="0">
<tbody>
<tr>
<td align="middle"><table class="border_pink" cellspacing="1" cellpadding="5" width="100%"
bgcolor="#e3017e" border="0">
<tbody>
<tr>
<td class="title" align="left" bgcolor="#f7d1e8">联络方式(不公开):</td>
</tr>
<tr>
<td align="middle" bgcolor="#ffffff"><table cellspacing="5" cellpadding="0" width="560" border="0">
<tbody>
<tr align="left">
<td width="75"><span class="STYLE1">*</span>联系电话1</td>
<td width="199"><input maxlength="15" name="PHONE1" />
</td>
<td width="72">联系电话2</td>
<td width="189"><input maxlength="15" name="PHONE2" /></td>
</tr>
<tr align="left">
<td> </td>
<td colspan="3">提醒:别忘记了输入区号,例如010-88888888</td>
</tr>
<tr align="left">
<td width="75">QQ 号码</td>
<td width="199"><input maxlength="14" name="QQ_NUM" />
</td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>住 址</td>
<td colspan="3"><input maxlength="50" size="60" name="ADDRESS" />
</td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>紧急联系人</td>
<td><input maxlength="10" name="CONNECTPERSON" /></td>
<td><span class="STYLE1">*</span>与您的关系</td>
<td><input maxlength="10" name="RELATION" /></td>
</tr>
<tr align="left">
<td><span class="STYLE1">*</span>联系电话</td>
<td><input maxlength="15" name="PERSONPHONE" /></td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>
<label>
<input name="Submit" type="submit" onclick="YY_checkform('form1','PHONE1','#q','1','Field \'PHONE1\' 必须填写','PHONE2','#q','1','Field \'PHONE2\' 必须填写','QQ_NUM','#q','1','Field \'QQ_NUM\' 必须填写','ADDRESS','#q','1','Field \'ADDRESS\' 必须填写','CONNECTPERSON','#q','1','Field \'CONNECTPERSON\' 必须填写','RELATION','#q','1','Field \'RELATION\' 必须填写','PERSONPHONE','#q','1','Field \'PERSONPHONE\' 必须填写');return document.MM_returnValue" value="提交" />
</label>
</form>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询