在写asp页面时,有时需要根据后台数据动态生成一些Js验证代码,比如订房系统需要根据房屋数量生成一个表格,让登陆者输入房间数,日期等信息,在提交表单时需要做非空验证,这样的js验证代码不好写死,应该动态生成,并输出。关于js代码中的单引号我试了好多次最后查到用chr(34)代替,并测试通过,现在将代码贴出来。
<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
<script language="javascript">
function checkdata()
{
if(document.djc_fs_kfyd.uname.value=="")
{
alert("请填入您的姓名!");
return false;
}
if(document.djc_fs_kfyd.IDnum.value=="")
{
alert("请填入您的证件号码!");
return false;
}
if((document.djc_fs_kfyd.IDnum.value).length !=18)
{
alert("请检验您的证件号码是否正确!");
return false;
}
if((document.djc_fs_kfyd.usize.value=="")||(isNaN(parseInt(document.djc_fs_kfyd.usize.value))))
{
alert("请填检查您填写的住人数!");
return false;
}
if(document.djc_fs_kfyd.rzrq.value=="")
{
alert("请填写入住日期!");
return false;
}
if(document.djc_fs_kfyd.ldrq.value=="")
{
alert("请填写离店日期!");
return false;
}
if(document.djc_fs_kfyd.telephone.value=="")
{
alert("填入您的联系电话!");
return false;
}
if(document.djc_fs_kfyd.mobile.value=="")
{
alert("请填入您的手机号码!");
return false;
}
return checkKF();
}
</script>
</head>
<body bgcolor="#FFFFFF">
<form action="djc_fs_kfyd_do.asp" name="djc_fs_kfyd" method="post" onSubmit="return checkdata() ">
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="images/index_01.jpg" width="780" height="173" alt=""></td>
</tr>
</table>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td rowspan="4"><img src="images/index_02.jpg" width="296" height="120" alt=""></td>
<td width="484" colspan="7" align="right"><img src="images/index_03.jpg" width="484" height="30" alt=""></td>
</tr>
<tr>
<td><a href="index.asp"><img src="images/index_04.jpg" alt="" width="50" height="21" border="0"></a></td>
<td><a href="gwly.asp"><img src="images/index_05.jpg" alt="" width="73" height="21" border="0"></a></td>
<td><a href="gnly.asp"><img src="images/index_06.jpg" alt="" width="80" height="21" border="0"></a></td>
<td><a href="djc_fs.asp"><img src="images/index_07.jpg" alt="" width="72" height="21" border="0"></a></td>
<td><a href="pwdl.html"><img src="images/index_08.jpg" alt="" width="73" height="21" border="0"></a></td>
<td><img src="images/index_09.jpg" width="72" height="21" alt=""></td>
<td><a href="xts_fz.html"><img src="images/index_10.jpg" alt="" width="64" height="21" border="0"></a></td>
</tr>
<tr>
<td colspan="7"><img src="images/index_11.jpg" width="484" height="29" alt=""></td>
</tr>
<tr>
<td colspan="7"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="156"><img src="images/index_12.jpg" width="156" height="40" alt=""></td>
<td background="images/index_13.jpg"><span class="zt_bq"><a href="gsjj.html" class="zt_bq">公司简介</a> | <a href="http://www.zhongjiagj.com" class="zt_bq">中嘉首页</a> | <a href="lxwm.html" class="zt_bq">联系我们</a> | </span><a href="rczp.asp" class="zt_bq">人才招聘</a></td>
<td width="80" align="right"><img src="images/index_14.jpg" width="80" height="40" alt=""></td>
</tr>
</table></td>
</tr>
</table>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="244" valign="top" bgcolor="#F0E3D0"><table width="0" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/index_15.jpg" width="244" height="61" alt=""></td>
</tr>
<tr>
<td><img src="images/index_21.jpg" width="244" height="99" alt=""></td>
</tr>
</table>
<table width="0" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><img src="images/index_23.jpg" width="244" height="53" alt=""></td>
</tr>
<tr>
<td height="102" colspan="2" align="center" background="images/index_33.jpg">
<marquee align="center" direction=up width="90" height="70" scrollamount=2 class="zt_xts" onmouseover=this.stop() onmouseout=this.start() >
<img src="images/index_gg.gif" width="4" height="6"> <a href="gswz.asp" title="中嘉洲际旅行社成功开通网站" target="_blank" class="zt_xts">网站开通</a><br>
<img src="images/index_gg.gif" width="4" height="6"> <a href="rczp.asp" title="最新人才招聘信息" target="_blank" class="zt_xts">人才招聘</a><br>
<img src="images/index_gg.gif" width="4" height="6"> <a href="xdwz.asp" title="兄弟网站成功开通" target="_blank" class="zt_xts">兄弟网站</a><br>
<img src="images/index_gg.gif" width="4" height="6"> <a href="hzdw.asp" title="近期合作单位信息" target="_blank" class="zt_xts">合作单位</a>
</marquee> </td>
</tr>
<tr>
<td rowspan="2"><img src="images/index_38.jpg" width="194" height="40" alt=""></td>
<td><a href="gonggao_all.asp"><img src="images/index_39.jpg" alt="" width="50" height="27" border="0"></a></td>
</tr>
<tr>
<td><img src="images/index_50.jpg" width="50" height="13" alt=""></td>
</tr>
<tr>
<td height="22" colspan="2" bgcolor="#F0E3D0"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/index_55.jpg" width="244" height="50" alt=""></td>
</tr>
<tr>
<td height="165" colspan="2" align="right" valign="top" background="images/index_60.jpg">
<script type="text/javascript">
function buildCal(m, y, cM, cH, cDW, cD, brdr){
var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
var dim=[31,0,31,30,31,30,31,31,30,31,30,31];
var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st
var todaydate=new Date() //DD added
var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added
dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0"><tr>';
t+='<td colspan="7" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr>';
for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"日一二三四五六".substr(s,1)+'</td>';
t+='</tr><tr>';
for(i=1;i<=42;i++){
var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : ' ';
if (x==scanfortoday) //DD added
x='<span id="today">'+x+'</span>' //DD added
t+='<td class="'+cD+'">'+x+'</td>';
if(((i)%7==0)&&(i<36))t+='</tr><tr>';
}
return t+='</tr></table></div>';
}
</script>
</head>
<body>
<script type="text/javascript">
var todaydate=new Date()
var curmonth=todaydate.getMonth()+1; //get current month (1-12)
var curyear=todaydate.getFullYear(); //get current year
document.write(buildCal(curmonth, curyear, "main", "month", "daysofweek", "days", 0));
</script>
<span class="zt_xts"><a href="rqcx.html" target="_blank" class="zt_xts"><br>
详细查询</a></span> </td>
</tr>
<tr>
<td><img src="images/rqcx_di.jpg" width="244" height="18"></td>
</tr>
</table></td>
<td width="52" valign="top" bgcolor="#F0E3D0"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/index_16.jpg" width="52" height="160" alt=""></td>
</tr>
<tr>
<td><img src="images/index_24.jpg" width="52" height="53" alt=""></td>
</tr>
<tr>
<td><img src="images/index_34.jpg" width="52" height="102" alt=""></td>
</tr>
<tr>
<td><img src="images/index_401.jpg" width="52" height="40" alt=""></td>
</tr>
<tr>
<td height="22" bgcolor="#F0E3D0"> </td>
</tr>
<tr>
<td><img src="images/gsjj_32.jpg" width="52" height="21" alt=""></td>
</tr>
<tr>
<td><img src="images/gsjj_33.jpg" width="52" height="194" alt=""></td>
</tr>
<tr>
<td><img src="images/rqcx_di01.jpg" width="52" height="18"></td>
</tr>
</table></td>
<td valign="top" bgcolor="#F0E3D0"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/djc_fs.jpg" width="484" height="43" alt=""></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="17" background="images/gsjj_18.jpg"> </td>
<td valign="top" bgcolor="#F0E3D0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" valign="middle" class="line_dw"><p align="center"><STRONG class="zt_xts">凤山温泉度假村网上预定</STRONG><STRONG><BR>
<BR>
</STRONG></p> </td>
</tr>
<tr>
<td valign="middle"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="30"><span class="zt_xts">姓名: </span></td>
<td><input name="uname" type="text" class="zt_bq" id="uname">
<span class="STYLE1">*</span></td>
</tr>
<tr>
<td><span class="zt_xts">身份证号:</span></td>
<td><input name="IDnum" type="text" class="zt_bq" id="IDnum">
<span class="STYLE1">*</span></td>
</tr>
<tr>
<td><span class="zt_xts">人数:</span></td>
<td><input name="usize" type="text" class="zt_bq" id="usize">
<span class="STYLE1">*</span></td>
</tr>
<tr>
<td class="zt_xts">入住日期:</td>
<td><input name="rzrq" type="text" class="zt_bq" id="id1" onClick="WdatePicker()"/>
<span class="STYLE1">*</span></td>
</tr>
<tr>
<td class="zt_xts">离店日期:</td>
<td><input name="ldrq" type="text" class="zt_bq" id="id2" onClick="WdatePicker()"/>
<span class="STYLE1">*</span></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="middle"><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#825C2D">
<tr bgcolor="#E1C6AA">
<td align="center" class="zt_xts">客房类型</td>
<td align="center" class="zt_xts">房间数</td>
<td align="center" class="zt_xts">进住时间</td>
<td align="center" class="zt_xts">退房时间</td>
<td align="center" class="zt_xts">备注</td>
</tr>
<%
clientJs="<script language="&chr(34)&"javascript"&chr(34)&">function checkKF(){if("
set rs1=server.createobject("adodb.recordset")
sql1="select distinct 项目类型 from 度假村价目表 where 所属单位='"&"凤山温泉度假村"&"' and 项目类别='"&"客房"&"'"
rs1.open sql1,cnn,3,3
if rs1.bof and rs1.eof then
response.write "<br>"&"<center class='zt_xts'>"&"系统暂时没有信息!"&"</center>"
else
i=1
while not rs1.eof
clientJs=clientJs&"(document.djc_fs_kfyd.fjs"&i&".value=="&chr(34)&""&chr(34)&")&&"
%>
<tr>
<td class="zt_xts"> <%=rs1("项目类型")%>
<input name="kflb<%=i%>" type="hidden" value="<%=rs1("项目类型")%>">
</td>
<td align="center"><input name="fjs<%=i%>" type="text" class="zt_bq" id="fjs" size="10"></td>
<td align="center"><input name="jzsj<%=i%>" id=d11 type="text" class="zt_bq" size="10" onClick="WdatePicker()"/></td>
<td align="center"><input name="tfsj<%=i%>" id=d11 type="text" class="zt_bq" size="10" onClick="WdatePicker()"/></td>
<td align="center"><input name="bz<%=i%>" type="text" class="zt_bq" id="bz" size="10"></td>
</tr>
<%
rs1.movenext
i=i+1
wend
end if
clientJs=left(clientJs,len(clientJs)-2)
clientJs=clientJs&"){alert("&chr(34)&"请您填写预定房间信息!"&chr(34)&"); return false;}}</script>"
%>
<input name="kfnum" type="hidden" value="<%=i-1%>">
</table></td>
</tr>
<tr>
<td valign="middle" class="line_dw"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="30"><span class="zt_xts">公司名称:</span></td>
<td><input name="company" type="text" class="zt_bq" id="company"></td>
</tr>
<tr>
<td><span class="zt_xts">电话:</span></td>
<td><input name="telephone" type="text" class="zt_bq" id="telephone">
<span class="STYLE1">*</span></td>
</tr>
<tr>
<td><span class="zt_xts">手机:</span></td>
<td><input name="mobile" type="text" class="zt_bq" id="mobile">
<span class="STYLE1">*</span></td>
</tr>
<tr>
<td><span class="zt_xts">传真:</span></td>
<td><input name="fax" type="text" class="zt_bq" id="fax"></td>
</tr>
<tr>
<td height="30"><span class="zt_xts">结帐方式:</span></td>
<td><input name="pay" type="text" class="zt_bq" id="pay"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="35" align="center" valign="middle"><input name="fs_kfyd" type="submit" class="zt_xts" id="fs_kfyd" value="提交">
<input name="fs_kfyd2" type="reset" class="zt_xts" id="fs_kfyd2" value="重写"></td>
</tr>
<tr>
<td height="20" valign="middle" class="line_dw"><span class="STYLE1">说明:其中带"*"项为必填项。</span></td>
</tr>
<tr>
<td height="50" align="center" valign="middle"><span class="zt_xts"><a href="djc_fs_kf.asp?ssdw=凤山温泉度假村&xmlb=客房" class="zt_xts">客房价目表</a> <a href="djc_fs_yl.asp?ssdw=凤山温泉度假村&xmlb=娱乐" class="zt_xts">娱乐价目表</a> <a href="djc_fs_hys.asp?ssdw=凤山温泉度假村&xmlb=会议室" class="zt_xts">会议室价目表</a> <a href="djc_fs_jlb.asp?ssdw=凤山温泉度假村&xmlb=俱乐部" class="zt_xts">俱乐部价目表</a></span></td>
</tr>
</table>
</td>
<td width="31" background="images/gsjj_20.jpg"> </td>
</tr>
</table></td>
</tr>
<tr>
<td><img src="images/main_di.jpg" width="484" height="18"></td>
</tr>
</table></td>
</tr>
</table>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="images/bottom.jpg" width="780" height="43"></td>
</tr>
</table>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="54" align="center" background="images/index_62.jpg"><span class="zt_xts">2008 中嘉国际 <br>
版权所有 侵权必究</span></td>
</tr>
</table>
</form>
</body>
</html>
<% response.Write(clientJs)%>