<html>
<script language="VbScript">
Function Cal()
Msgbox(document.oForm.oDate1.value)
document.oForm.oDate2.value = DateAdd(document.all.oSel.value, 1, document.oForm.oDate1.value)
End Function
</script>
<body>
<form name="oForm">
签定日<input type="text" name="oDate1" id="oDate1"><br>
限期<input type="text" name="oNum" id="oNum" size="5">
<select name="oSel" id="oSel">
<option value="YYYY">年</option>
<option value="M">月</option>
<option value="D">日</option>
</select>
到期日<input type="text" name="oDate2" id="oDate2"><br>
<input type="button" onclick="Cal()" value="caculate">
</form>
</body>

解决方案 »

  1.   

    <html>
    <script language="VbScript">
    Function DateToStr(datestring)
    Dim datestr, yearstr, monthstr, daystr, hourstr, minutestr, secondstr
    datestr="" If IsNull(datestring) Or datestring = "" Then
    DateToStr = ""
    Exit Function
    End If yearstr = DatePart("yyyy", datestring)
    datestr = datestr & yearstr
    datestr = datestr & "-" monthstr = DatePart("m", datestring)
       If CInt(monthstr)<10 Then
    monthstr = "0" & monthstr
    End If
    datestr = datestr & monthstr
    datestr = datestr & "-"   daystr = DatePart("d", datestring)
    If CInt(daystr) < 10 Then
    daystr = "0" & daystr
    End If
    datestr = datestr & daystr DateToStr = datestr
    End Function
    Function Cal()
    Dim s
    s = DateToStr(DateAdd(document.all.oSel.value, 1, document.oForm.oDate1.value))
    document.oForm.oDate2.value = s
    End Function
    </script>
    <body>
    <form name="oForm">
    签定日<input type="text" name="oDate1" id="oDate1"><br>
    限期<input type="text" name="oNum" id="oNum" size="5">
    <select name="oSel" id="oSel">
    <option value="YYYY">年</option>
    <option value="M">月</option>
    <option value="D">日</option>
    </select>
    到期日<input type="text" name="oDate2" id="oDate2"><br>
    <input type="button" onclick="Cal()" value="caculate">
    </form>
    </body>
      

  2.   

    <form method="POST" action="" name=form1>
    合同签订日期:<input type=text name=datastart><br>
    &nbsp;&nbsp;&nbsp; 合同期限:<input type=text name=times size=3>&nbsp;&nbsp;&nbsp; 
    <input type="radio" value="V1" checked name="R1">年<input type="radio" name="R1" value="V2">月<br>
    &nbsp;&nbsp;&nbsp;&nbsp; <input type="button" value="提交" onclick=Post()><input type=hidden name=dataend>
    </form>
    <script>
    function Post(){

    d1=new Date(document.all.datastart.value);
    yy=d1.getFullYear();
    mm=d1.getMonth();
    dd=d1.getDate();
    d2=document.all.times.value;
    if (document.all.V1[0].checked) yy+=d2*1;
        else mm+=d2*1
        d1.setFullYear(yy,mm,dd);
        document.all.dateend.value=d1.getFullYear()+"-"+(d1.Month()+1)+"-"+d1.getDate();
    //    form1.submit();

    }
    </script>
      

  3.   

    帮8988更正几处笔误
    算出的到期时间若须隐含,将<input type=text name=dateend>中type再写为hidden。签订日期需要以yy/mm/rr形式输入
    <form method="POST" action="" name=form1>
    合同签订日期:<input type=text name=datastart><br>
    &nbsp;&nbsp;&nbsp; 合同期限:<input type=text name=times size=3>&nbsp;&nbsp;&nbsp; 
    <input type="radio" value="V1" checked name="R1">年<input type="radio" name="R1" value="V2">月<br>
    &nbsp;&nbsp;&nbsp;&nbsp; <input type="button" value="提交" onclick=Post()>
    合同到期日期:<input type=text name=dateend>
    </form>
    <script>
    function Post(){
    d1=new Date(document.all.datastart.value);
    yy=d1.getFullYear();
    mm=d1.getMonth();
    dd=d1.getDate();
    d2=document.all.times.value;
    if (document.all.R1[0].checked) yy+=d2*1;
        else mm+=d2*1
        d1.setFullYear(yy,mm,dd);
        document.all.dateend.value=d1.getFullYear()+"-"+(d1.getMonth()+1)+"-"+d1.getDate();
    }
    </script>
      

  4.   

    <form method="POST" action="" name=form1>
    合同签订日期:<input type=text name=datastart><br>
    &nbsp;&nbsp;&nbsp; 合同期限:<input type=text name=times size=3>&nbsp;&nbsp;&nbsp; 
    <input type="radio" value="V1" checked name="R1">年<input type="radio" name="R1" value="V2">月<br>
    &nbsp;&nbsp;&nbsp;&nbsp; <input type="button" value="提交" onclick=Post()>
    合同到期日期:<input type=text name=dateend>
    </form>
    <script>
    function Post(){
        var sDate = document.all.datestart.value ;
         sDate  = sDate.replace(/-/g,"/") ;
        d1=new Date(sDate);
        yy=d1.getFullYear();
        mm=d1.getMonth();
        dd=d1.getDate();
        d2=document.all.times.value;
        if (document.all.R1[0].checked) yy+=d2*1;
        else mm+=d2*1
        d1.setFullYear(yy,mm,dd);
        document.all.dateend.value=d1.getFullYear()+"-"+(d1.getMonth()+1)+"-"+d1.getDate();
    }
    </script>
    还是加点东西吧。
      

  5.   

    BrentIvan的方法也很好哦,只要将期限参数传过去就可以了。签订日期可以"/"、","、"-"和空格等多种方式间隔,只是少了输入出错校验<html>
    <script language="VbScript">
    Function Cal()
    'Msgbox(document.oForm.oDate1.value)
    document.oForm.oDate2.value = DateAdd(document.all.oSel.value, document.oForm.oNum.value, document.oForm.oDate1.value)
    End Function
    </script>
    <body>
    <form name="oForm">
    签定日<input type="text" name="oDate1" id="oDate1"><br>
    限期<input type="text" name="oNum" id="oNum" size="5">
    <select name="oSel" id="oSel">
    <option value="YYYY">年</option>
    <option value="M">月</option>
    <option value="D">日</option>
    </select>
    到期日<input type="text" name="oDate2" id="oDate2"><br>
    <input type="button" onclick="Cal()" value="caculate">
    </form>
    </body>