Javascript date problem

Discussion in 'JavaScript' started by StealthRT, Apr 26, 2006.

  1. #1
    Hey all i need to find a way to check to see if the user clicked on a date thats in the future (ie. a date thats pass todays date)

    Code:
    
    onClick="if(self.gfPop)gfPop.fPopCalendar(document.frmSurvey.dc);return false;"
    
    Code (markup):
    The date is formatted like 04/14/2006

    If today was the 14 and the user tryed to click any date after the 14th then i need it to blank out the frmSurvey.dc text box and tell them they can not select that date... or if thats hard then simply clear the text box.

    Thanks for your help,
    David
     
    StealthRT, Apr 26, 2006 IP
  2. dexfantasy

    dexfantasy Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not sure if this is the best way to do it, but I'd do something like

    IF currentyear < selectedyear
    or if currentyear == selectedyear and currentmonth < selectedmonth
    or if currentyear == selectedyear and currentmonth == selectedmonth and currentday < selectedday
    THEN
    clear the textbox
    Code (markup):
    So, in javascript, it might look something like this

    var datestring = "04/27/2008";
    var d = new Date();
    var cd = [d.getMonth() + 1, d.getDate(), d.getFullYear()]; // current date
    var sd = datestring.split('/');  // selected date
    if ( cd[2] < sd[2] || cd[2] == sd[2] && cd[0] < sd[0] || cd[2] == sd[2] && cd[0] == sd[0] && cd[1] < sd[1] )
      document.frm.dc.value = "";
    Code (markup):
     
    dexfantasy, Apr 27, 2006 IP
  3. StealthRT

    StealthRT Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Where would i put that code with the code i already have?

    David
     
    StealthRT, Apr 28, 2006 IP
  4. StealthRT

    StealthRT Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here is the .html file that it used to show the calender and stuff...

    David
     

    Attached Files:

    StealthRT, Apr 28, 2006 IP
  5. dexfantasy

    dexfantasy Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    a. the code you are working with is copyrighted
    b. the code you gave me relies on code you didn't give me
    c. i don't get the sense that you are putting in much an effort to solve this yourself. I'm new here, so I don't mean to be presumptuous, but I'm guessing you will have better luck at a site like rentacoder.com.

    Dex
     
    dexfantasy, Apr 28, 2006 IP
  6. StealthRT

    StealthRT Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Then consider this topic deleted....
     
    StealthRT, Apr 28, 2006 IP
  7. michael.heliso

    michael.heliso Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    In case you will have issues with JavaScript Date here are some useful functions: http://dotnetcaffe.blogspot.com
     
    michael.heliso, Dec 3, 2009 IP
  8. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #8
    An easier way is to just create a date object from the string and compare the dates:
    
    var datestring = "12/06/2009";
    var now = new Date();
    datestring = new Date(datestring);
    if(datestring>now) {
        //do whatever now
    }
    
    Code (markup):
    Just for reference anyway
     
    camjohnson95, Dec 3, 2009 IP