日期:2014-05-16  浏览次数:20562 次

高手,救火,在线等....
我在表单中输入一个日期,然后再在从数据库中调出我以前的日期,两个日期比较,如果输入的日期比数据库中的日期小,则弹出对话框,重新输入.
代码如下:
<%
Dim   cc,id
Dim   back_date
id=Request( "id ")
Set   cc   =   Conn.Execute( "Select   *   From   [takeshou]   Where   ID= "&id)
back_date=cc( "take_date ")
%>
<script   language= "JavaScript ">
<!--
function   chk(theForm){  
if   (theForm.take_date.value   请问这里怎么写)
                                alert( "请输入领料日期! ");
                                theForm.amount.focus();
                                return   (false);
                }  

}
//-->
</script>
<form   action= "wushou_Add2.asp "   method=post   id=form1   name=form1   onSubmit= "return   chk(this) ">
  <input   name= "take_date "   type= "text "   id= "take_date ">
<input   type= "submit "   name= "Submit "   value= "添   加 ">

  <input   name= "take_date "   type= "text "   id= "take_date ">
take_date为从文本框输入的日期
back_date为从数据库取出的日期

------解决方案--------------------
<script language= "JavaScript ">
function checkDateEarlier()
{
var strStart=document.getElementById( "take_date ").value;
var strEnd= " <%=back_date%> ";
var arr1 = strStart.split( "- ");
alert(arr1[1].length);
var arr2 = strEnd.split( "- ");
var date1 = new Date(arr1[0],parseInt(arr1[1].replace(/^0/, " "),10) - 1,arr1[2]);
var date2 = new Date(arr2[0],parseInt(arr2[1].replace(/^0/, " "),10) - 1,arr2[2]);
if (arr1[1].length==1)
arr1[1] = "0 " + arr1[1];
if (arr1[2].length==1)
arr1[2] = "0 " + arr1[2];
if (arr2[1].length==1)
arr2[1] = "0 " + arr2[1];
if (arr2[2].length==1)
arr2[2]= "0 " + arr2[2];
var d1 = arr1[0] + arr1[1] + arr1[2];
var d2 = arr2[0] + arr2[1] + arr2[2];
if(parseInt(d1,10)> parseInt(d2,10)){
//alert( "no ");
return false;
}
else{
alert( "小于入库日期 ");
return true;
}

}//~~~

//-->
</script>
<form action= "wushou_Add2.asp " method=post id=form1 name=form1 onSubmit= "return checkDateEarlier() ">
<input name= "take_date " type= "text " id= "take_date ">
<input type= "submit " name= "Submit " value= "添 加 " >
</form>