Populated Date in Text Field

This question already has an answer here:

  • How do I get the current date in JavaScript? 39 answers

  • Date.getMonth:

    The value returned by getMonth is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.

    Reference.


    HTML Element:

    <p>Today's Date<br />
    <input id="date" type="text" name="curDate" size="50" /><br />
    Pick-up Date<br />
    <input type='text' name='duedateField' id='duedateField' value='' /></p>
    

    Use this javascript:

    var month = Date.getMonth();
    var date = Date.getDate();
    var year = Date.getYear();
    var deliverymonth;
    var deliverydate;
    var deliveryyear;    
    
    
    var message = month + "/" + date + "/" + year;
    document.getElementById('date').innerHTML=message;
    if(month == 11 && date >= 29){
        deliveryyear = year + 1;
        deliverymonth = 1;
        deleverydate = date - 28;
    }else{
    
    
         switch(month)
        {
            case 0,2,4,6,7,9,11:
                 if(date >= 29){
                     deliverymonth = month + 1;
                     deliverydate = date - 28;
                 }else{
                     deliverydate = date + 3;
                 }
                 break;
             case 3,5,8,10:
                 if(date >= 28){
                     deliverymonth = month + 1;
                     deliverydate = date - 27;
                 }else{
                     deliverydate = date + 3;
                 }
                 break;
              case 1:
                 if(date >= 26){
                     deliverymonth = month + 1;
                     deliverydate = date - 25;
                 }else{
                     deliverydate = date + 3;
                 }
                 break;
              default:
                 break;
              }
    var deliverymessage = deliverymonth + "/" + deliverydate + "/" + deliveryyear;
    document.getElementById('duedateField').innerHTML=deliverymessage;
    
    链接地址: http://www.djcxy.com/p/77518.html

    上一篇: 使用JavaScript提醒功能显示日期

    下一篇: 文本字段中的填充日期