SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Comparison Date

  1. #1
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    408
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Comparison Date

    Hello everyone.

    I have this html page:


    PHP Code:
    <html>
     
    <
    head>
     
    </
    head>
     
    <
    body>
     
    <
    select size="1" name="date_1" onChange="window.location.href='Tot.asp?date_2=24/04/2008&date_1='+this.options[this.selectedIndex].value;">
    <
    option>select</option>
    <
    option value="11/03/2008">11/03/2008</option>
    <
    option value="12/03/2008">12/03/2008</option>
    <
    option value="13/03/2008">13/03/2008</option>
    <
    option value="14/03/2008">14/03/2008</option>
    <
    option value="17/03/2008">17/03/2008</option>
     
    </
    select>
             
    <
    select size="1" name="date_2" onChange="window.location.href='Tot.asp?date_1=24/04/2008&date_2='+this.options[this.selectedIndex].value;">
    <
    option>select</option
    <
    option value="11/03/2008">11/03/2008</option>
    <
    option value="12/03/2008">12/03/2008</option>
    <
    option value="13/03/2008">13/03/2008</option>
    <
    option value="14/03/2008">14/03/2008</option>
    <
    option value="17/03/2008">17/03/2008</option>
    </
    select>
     
     
    </
    body>
     
    </
    html
    I would like javascript function check that:

    date_1 = 24/04/2008
    date_2 = 25/04/2008

    it's right....

    date_1 = 25/04/2008
    date_2 = 24/04/2008

    it's wrong....

    Check that date_2 always higher date_1, it's possible?

    This page is not a form...nothing submit button, only onchange event.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't really make sense to have form controls without a form, but here's a way to compare the dates.
    Code JavaScript:
    /* d1, d2 are the selected option values */
    function check(d1, d2) {
        if (d1 !== "select" && d2 !== "select") {
            var n1 = parseInt(d1.split("/").reverse().join(""), 10);
            var n2 = parseInt(d2.split("/").reverse().join(""), 10);
            if (n2 > n1) {
                alert(n2+" is later than "+n1);
            } else {
                alert(n2+" is NOT later than "+n1);
            }
        }
    }
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    408
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    thanks for your reply!


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
  •