dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Desperate help needed

  1. #1
    Join Date
    Mar 2003
    Posts
    2

    Question Desperate help needed

    Hi
    I have aproblem in that I need to enter a date in format dd/mm/yy into a web page text box and on same form another text box should fill out 10 days in furure.

    If some one can help me I would be most appreciated.
    In vbscript I can do it easily but client side scripting of dates has me beat.
    Don

  2. #2
    Join Date
    Jan 2003
    Location
    Peg City
    Posts
    638
    Use this to update it on the fly:

    <form name="formname">

    <input type=text name="date1" onKeyUp=document.formname.date2.value=this.value>

    <input type=text name="date2">

    </form>

    As for dates, I'll look at this and get back to you

    Havik

  3. #3
    Join Date
    Jan 2003
    Location
    Peg City
    Posts
    638
    This works for ten days ago, but I get NaN when I try to get 10 days ahead.

    <script language="JavaScript">

    today = new Date();
    tendays = new Date(today - (10*(24*60*60*1000)));
    alert(tendays);

    </script>

    Change this:
    tendaysago = new Date(today - (10*(24*60*60*1000)));

    To this to attempt ten days ahead
    tendays = new Date(today + (10*(24*60*60*1000)));

    (24*60*60*1000) represents a day, so times 10 it represents 10 days.

    See if that works for you, maybe I'm doing something wrong.

    Havik

  4. #4
    Join Date
    Mar 2003
    Posts
    2
    Thanks havik
    I tried it but get the same, I really an desperate but dont have clue about java script.

    I have this and it works kind of but does not take into accounts month length and on 2,4,8,11 month it adds a month and 10 days.
    I really appreciate your help....


    <script type="text/javascript" language="JavaScript">
    <!-- HIDE FROM OLD BROWSERS
    function validateInput(x){
    oldd="Inputstring: "+x+"<br>";
    a=x.split('/');

    oldy=1*a[2] ;
    // 1* makes a numbervalue from a string
    if (oldy<35) oldy+=2000;
    if (oldy<100) oldy+=1900;
    // 1- or 2-number year split at 1935

    now=new Date();
    now.setFullYear(oldy);
    now.setMonth(1*a[1]-1);
    // setMonth: Januari=0
    now.setDate(a[0]);

    thn=new Date(1*now+9*24*60*60*1000);
    d=thn.getDate();
    m=thn.getMonth()+1;
    y=thn.getFullYear();
    d=((d<10)?"0":"")+d;
    // change 9 to 09
    m=((m<10)?"0":"")+m;
    s="/";
    newd=+d+s+m+s+y;

    this.addtransadmin.inputdemurrdate.value=newd;
    }
    // STOP HIDING -->
    </script>

  5. #5
    Join Date
    Jan 2003
    Location
    Peg City
    Posts
    638
    I test the code yesterday and there were problems, today though it runs perfectly. None of the months add a month and ten days and it even accounts for the end of each month, even February. I didn't really change the code at all, I just added a few parenthesis for my own sake and that's all.

    If this doesn't work on your computer then something is up with the dates. In this case, it's probably the current date that is messing around with this script somehow.

    Havik

    <script type="text/javascript" language="JavaScript">
    <!-- HIDE FROM OLD BROWSERS
    function validateInput(x){
    oldd="Inputstring: "+x+"<br>";
    a=x.split('/');

    oldy=1*a[2] ;

    // 1* makes a numbervalue from a string
    if (oldy<35) oldy+=2000;
    if (oldy<100) oldy+=1900;
    // 1- or 2-number year split at 1935

    now=new Date();
    now.setYear(oldy);
    now.setMonth((1 * a[1]) - 1);
    // setMonth: Januari=0
    now.setDate(a[0]);

    thn=new Date((1*now)+(9*24*60*60*1000));
    d=thn.getDate();
    m=thn.getMonth()+1;
    y=thn.getFullYear();
    d=((d<10)?"0":"")+d;
    // change 9 to 09
    m=((m<10)?"0":"")+m;
    s="/";
    newd=d+s+m+s+y;

    alert(newd);
    }
    // STOP HIDING -->
    </script>
    </head>

    <body>

    <a href="#" onclick="validateInput('28/2/03')">test</a>


    </body>

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