jQuery/javascript/bootstrap - Working with datepicker, combining two scripts, StartDate/EndDate
I have two sets of code, both which work on their own, but I'm really struggling to combine the two.
What I'm trying to do is control start date / end date entries into respective textboxes with datepicker.
When the start date is selected, the date picker disables dates before that selected date when the other text box is clicked.
Also, only days up until the next Sunday (from the selected start date) can be selected as an end date.
So this code works to disable any previous dates for the endDate textbox.
var dateFormat = "mm/dd/yy"; var from = $(".start").datepicker({ changeMonth: true, numberOfMonths: 1 }).on("change", function () { to.datepicker("option", "minDate", getDate(this)); }); var to = $(".end").datepicker({ changeMonth: true, numberOfMonths: 1 }).on("change", function() { from.datepicker("option", "maxDate", getDate(this)); }); function getDate(element) { var date; try { date = $.datepicker.parseDate(dateFormat, element.value); } catch (error) { date = null; } return date; }
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst