We help IT Professionals succeed at work.
Get Started

Datepicker set period after specified time

darren-w-
darren-w- asked
on
951 Views
Last Modified: 2012-08-20
Hi,

Setting up a direct debit page, the user specifies the date for the first payment and then can pick on the end date for payments.

They need to pick on a defined period (ie monthly, weekly, 6 monthly...) and the end date cannot be before this.

so if a user picks a start date that is in 14 days+ time and the period is set to monthly the earliest end date cannot be before a month after the start date.

So the present code in snippets:

    jQuery("#start_date").datepicker({
        dateFormat: 'dd/mm/yy',
        changeMonth: true,
        beforeShowDay: jQuery.datepicker.noWeekends,
        minDate:14,
               onSelect: function( selectedDate ) {
            $( "#Enter_date" ).datepicker( "option", "minDate", selectedDate );
        }
    });
   
    jQuery("#Enter_date").datepicker({
        dateFormat: 'dd/mm/yy',
        changeMonth: true,
        beforeShowDay: jQuery.datepicker.noWeekends
 
    });

Open in new window


this is a function I'm using to work out the period as required by the datepicker:
function setDate(){
    var freq = jQuery('#frequency option:selected').attr('label');
    var twovalue;
    var retString;
    if(freq.indexOf(' ') >= 0){
        twovalue=  freq.split(' ');
    }
    if (freq.indexOf(' ') >= 0){
        twovalue=  freq.split(' ');
        var freqNo = twovalue[0];
        var freqPeriod = twovalue[1].charAt(0).toLowerCase();
        retString = "+"+freqNo+freqPeriod
    }else if(freq.toLowerCase() == "fortnight"){
        retString = "+2w";
    }else{
        retString = "+1"+ freq.charAt(0).toLowerCase();
    }
    jQuery("#Enter_date").datepicker("option","minDate",retString);
}

Open in new window


Though I think some native date manipulation may be required
Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE