www.webdeveloper.com
Results 1 to 4 of 4

Thread: NEED Script to ADD 1 day to the previous date field

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    6

    NEED Script to ADD 1 day to the previous date field

    My form has 7 date fields(sun, mon, tue, wed, thur, fri, sat). I would like to be able to enter any date in the 'sun' field and have the rest automatically fill in adding 1(one) day consecutively. My date is formatted at mm/dd/yyyy.

    I have done my research and found several answers that other people have had success with, however nothing has worked for me. Im guessing that its not the script I am getting wrong, but rather something not set right in the properties.

    Also, I know with this script there is an issue with daylight savings, but at this point I am not to concerned with that

    thanks

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,268
    Use the Date object :
    Code:
    var myDate=new Date(yyyy,mm-1,dd);
    var nextDate=new date(myDate.getFullYear(),myDate.getMonth(),myDate.getDate()+1);

  3. #3
    Join Date
    Apr 2014
    Posts
    6
    Quote Originally Posted by 007Julien View Post
    Use the Date object :
    Code:
    var myDate=new Date(yyyy,mm-1,dd);
    var nextDate=new date(myDate.getFullYear(),myDate.getMonth(),myDate.getDate()+1);
    Thanks OO7

    While waiting for a reply I also found this script.

    //Custom Validate script
    (function () {

    // Clear other field if field is blank
    if (!event.value) {
    getField("mo").value = "";
    return;
    }

    // Convert value to a date object
    var d = util.scand("mm/dd/yyyy", event.value);

    // Add one day
    d.setDate(d.getDate() + 1);

    // Set the value of the other date field
    getField("mo").value = util.printd("mm/dd/yyyy", d);

    })();


    This worked for the first five days, I cant get it to work for the last two.

    Any ideas?

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,268
    A simple page to full a form with the dates of the current week :
    Code:
    <!DOCTYPE>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="generator" content="PSPad editor, www.pspad.com">
    <title></title>
    <style type="text/css">
    body{background:#ccc;color:#fff;}
    #pge {display:block;width:600px;margin:20px auto;padding:7px;background:#666}
    td input {display:block;width:70px;}
    table{margin:0 auto;}
    </style>
    </head>
    <body>
    <div id="pge"><fieldset><legend>Working with weeks</legend>
    <form id="">
        <table><tr><td>sun</td><td>mon</td><td>tue</td><td>wed</td><td>thu</td><td>fri</td><td>sat</td></tr>
        <tr><td><input id="dy0" type="text"></td><td><input id="dy1" type="text"></td><td><input id="dy2" type="text"></td><td><input id="dy3" type="text"></td><td><input id="dy4" type="text"></td><td><input id="dy5" type="text"></td><td><input id="dy6" type="text"></td></tr>
        </table>
    </form>
    </fieldset>
    </div>
    <body>
    <script type="text/javascript">
    var i,m,d,tdy=new Date(),currentDay=new Date;// The date
    while (currentDay.getDay()) currentDay.setDate(currentDay.getDate()-1);// We go back to find the first sunday before
    for (i=0;i<7;i++) {m=+currentDay.getMonth()+1;d=+currentDay.getDate();// the month and date
        document.getElementById('dy'+i).value=(m<10?'0':'')+m+'/'+(d<10?'0':''+d)+'/'+tdy.getFullYear();
        currentDay.setDate(currentDay.getDate()+1);// we went through the week
    }
    </script>
    </body>
    </html>
    Last edited by 007Julien; 04-25-2014 at 01:58 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles