48 users online (1 members and 47 guests)  


  Results 1 to 2 of 2

Related

  1. Format messed up    Forum: HTML Forum
    Replies: 4
  2. How to format Mb numbers?    Forum: CGI Perl Forum
    Replies: 1
  3. Matching a certain date format from a String?    Forum: CGI Perl Forum
    Replies: 0
  4. I like ur new format...    Forum: HTML Forum
    Replies: 6
  1. #1
    proctk's Avatar
    New User

    Status
    Offline
    Join Date
    Feb 2006
    Posts
    5

    Text Object as date format

    Hi.

    I have a text object on a form where the user keys a date 01/01/2006.

    What I want to happen is I want the value in another textboject on the form to be treated as a value to add to the date to get some future date.

    in this text object the value could be 15, this value needs to be mutiplied buy 7 then added to the above date.

    Based on the above date the value would be 04/16/06

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Text Object as date format

    Hi there proctk,

    try this little offering, it may suit your requirements....

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>future date</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    <!--
    div {
        width:450px;
        border:3px double #000;
        padding:10px;
        margin:30px auto;
        background-color:#ccc;
        color:#000;
     }
    input {
        width:100px;
        margin:4px;
        font-size:16px;
     }
    -->
    </style>
    
    <script type="text/javascript">
    <!--
      var mos=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
      var df=document.forms;
    
    function futureDate() {
    
       now=df[0][0].value;
       mm=now.split('/')[0];
       dd=now.split('/')[1];
       yy=now.split('/')[2];
       nowstr=yy+','+dd+','+mos[mm-1];
    
       weeks=df[0][1].value*7*60*60*1000*24;
       nowsecs=Date.parse(nowstr)+weeks;
    if(isNaN(nowsecs)) {
       alert('please enter data as indicated');
       df[0].reset();return;
     }
    
       later=new Date(nowsecs);
       lm=later.getMonth()+1;
    if(lm<10) {
       lm='0'+lm;
     }
       ld=later.getDate();
    if(ld<10) {
       ld='0'+ld;
     }
       ly=later.toDateString().split(' ');
    
       df[0][2].value=lm+'/'+ld+'/'+ly[3];
     }
    //-->
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <div>
    <input type="text" value="mm/dd/yyyy" onfocus="this.value=''">
    <label> : insert date in this style...mm/dd/yyyy</label><br />
    <input type="text" value="weeks" onfocus="this.value=''">
    <label> : insert number of weeks</label><br />
    <input type="text" readonly="readonly">
    <label> : this is the future date</label><br />
    <input type="button" value="future date" onclick="futureDate()"><input type="reset" value="clear values">
    </div>
    </form>
    
    </body>
    </html>



Tags for this Thread