www.webdeveloper.com
Results 1 to 6 of 6

Thread: Date Picker

  1. #1
    Join Date
    Nov 2006
    Posts
    11

    Date Picker

    Hi,
    Haven't posted for a while so please bear with me. I have a date picker which I sourced from http://www.nsftools.com/tips/DatePickerTest.htm & it works really well.
    I've now been asked if there is anyway to exclude the user from selecting the current month or make it default to 4 weeks ahead?? I have looked at the source code & am by no means a javascript expert .
    Could you please take a look & see what lines I need to change in order to achieve my goal??

    I have attached the code in a zip file as I couldn't include it in this post
    thanks,
    john.
    Attached Files Attached Files

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    function refreshDatePicker(dateFieldName, year, month, day)
    {
      // if no arguments are passed, use today's date; otherwise, month and year
      // are required (if a day is passed, it will be highlighted later)
      var thisDay = new Date();
     
      if ((month >= 0) && (year > 0)) {
        thisDay = new Date(year, month+1, 1);
      } else {
        day = thisDay.getDate();
        thisDay.setDate(1);
      }
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Nov 2006
    Posts
    11
    Fang,
    This works for the initial datepicker but if they choose a date of say '18/08/2008' & then decide to change this it then loads the month of September & there is no way of going back to August!!!

    Anymore help??

    Thanks.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    In function drawDatePicker
    Code:
    refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth()+1, dt.getDate());
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Nov 2006
    Posts
    11
    Fang,

    This increases the month each time by 1 & they can still go back & choose the month I want to be excluded.

    eg.
    If I want to exclude July, then this code will open the calender up in August, but they can still use the arrows to go back to July.

    John.

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    function getButtonCode(dateFieldName, dateVal, adjust, label)
    {
      var DateToday=new Date();
      adjust = ( (dateVal.getMonth () + adjust)< (DateToday.getMonth()+1) )? 0 : adjust;
      var newMonth = (dateVal.getMonth () + adjust) % 12;
      //alert(dateVal.getMonth() + adjust+":"+newMonth)
      var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
      if (newMonth < 0) {
        newMonth += 12;
        newYear += -1;
      }
     
      return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ");'>" + label + "</button>";
    }
    At least 98% of internet users' DNA is identical to that of chimpanzees

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