SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript pop up for date specific drop down

    Below is a function I have for date check on an online booking form. What I want to achieve is for an alert to pop up when the user tries to book with 2 days of today's date(the current date).

    ***************************************************

    function checkdate(){
    flag=0;
    dsd = new Array();
    ded = new Array();
    sdate=document.frm.startrentday[document.frm.startrentday.selectedIndex].value;
    sdate=(sdate<10)?"0"+parseInt(sdate):sdate;
    smonth=document.frm.startrentmonth[document.frm.startrentmonth.selectedIndex].value;
    smonth=(smonth<10)?"0"+parseInt(smonth):smonth;
    syear=document.frm.startrentyear[document.frm.startrentyear.selectedIndex].value;
    syear=(syear<10)?"0"+parseInt(syear):syear;
    dsd=valid_date;
    //alert(dsd);
    dsd[1]=(dsd[1]<10)?"0"+parseInt(dsd[1]):dsd[1];
    dsd[2]=(dsd[2]<10)?"0"+parseInt(dsd[2]):dsd[2];
    //dsd=dsd.reverse();
    dsd1=dsd.join("");
    csd=(syear+""+smonth+""+sdate);
    //alert (Number(csd)+"\n"+Number(dsd1));
    if((Number(csd)>=today_date) && (Number(csd)<today_date+2)){
    alert("If you need to hire a vehicle within the next 48 hours.\nPlease contact our office +353 62 53103");
    return false;
    }else if(Number(csd)<today_date){
    alert("Do not select Previous start date");
    return false;
    }

    *************************************************

    The today_date variable is fine. It was defined outside this function.

    When I have today_date+2, the alert shows for dates after a two day period.

    Is there any way, from looking at my code, that you can see of having the alert pop up only for dates that are two days and less.

    I'd really appreciate any help.

    Thanks

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if this helps? Basically it calculates how many seconds its been between today and the date given, and then devides it by the amount of seconds within a day (roughly).

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Untitled Document</title>
            <link rel="stylesheet" type="text/css" media="screen" />
            <script type="text/javascript">
                function validateDate(val) {
                    var d = new Date(val);
                    if(Math.round((new Date()-d)/86400000)<=2)
                        alert('Date within 2 days of today');
                }
                window.onload = function() {
                    validateDate('07/30/2007 16:30:00');
                };
            </script>
        </head>
        <body>
            
            
    
        </body>
    </html>



Bookmarks

Posting Permissions

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