Date_2 always higher Date_1 in the selectIndex

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #16
    Remove line 33.

    Line 34 should go where line 13 is, i.e. after line 12. Do you understand where you went wrong? join() is a method of an Array object and you made date1 into a string.

    Repeat the empty string check for date2 too.

    Comment

    • Mike1961
      New Member
      • Apr 2008
      • 66

      #17
      Originally posted by acoder
      Remove line 33.

      Line 34 should go where line 13 is, i.e. after line 12. Do you understand where you went wrong? join() is a method of an Array object and you made date1 into a string.

      Repeat the empty string check for date2 too.

      No, not understand.... :-(

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #18
        [code=javascript]function validateDate()

        {
        var date1, date2, date_1, date_2;
        // get date1 value
        date1 = document.getEle mentById("date1 ").value;
        if (date1 == "") return;
        // split the values to get the date/month/year
        date1 = date1.split("/");
        //create new date object
        date_1 = new Date();
        // set the date - see ref
        date_1.setFullY ear(date1[2],date1[1]-1,date1[0]);

        // repeat for date2...
        // get date2 value
        date2 = document.getEle mentById("date2 ").value;
        if (date2 == "") return;
        // split the values to get the date/month/year
        date2 = date2.split("/");
        //create new date object
        date_2 = new Date();
        // set the date - see ref
        date_2.setFullY ear(date2[2],date2[1]-1,date2[0]);

        //...
        // now compare
        if ( date_1 > date_2 )

        {
        alert ("Stop");
        }

        else

        {
        window.location .href = 'index.htm?date _1=' + encodeURICompon ent(date1.join( "/")) + '&date_2=' + encodeURICompon ent(date2.join( "/"));

        }
        }[/code]

        Comment

        • Mike1961
          New Member
          • Apr 2008
          • 66

          #19
          Try this....

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #20
            Your option values don't match the text for each option, e.g.
            [html]<option value="19/07/2007">19/08/2007</option>[/html]

            Comment

            • Mike1961
              New Member
              • Apr 2008
              • 66

              #21
              Originally posted by acoder
              Your option values don't match the text for each option, e.g.
              [html]<option value="19/07/2007">19/08/2007</option>[/html]
              thanks, I am distracted and a disaster... :-)

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #22
                So does that mean it's all working fine now?

                Comment

                • Mike1961
                  New Member
                  • Apr 2008
                  • 66

                  #23
                  Originally posted by acoder
                  So does that mean it's all working fine now?
                  Yes, your script working well, very well...
                  thanks !

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #24
                    You're welcome.

                    One final point: if you understand the script, you can remove all the extra comments (lines starting with //).

                    Comment

                    • Mike1961
                      New Member
                      • Apr 2008
                      • 66

                      #25
                      Originally posted by acoder
                      You're welcome.

                      One final point: if you understand the script, you can remove all the extra comments (lines starting with //).
                      OK...... !!!
                      Regards,

                      Comment

                      Working...