views:

315

answers:

1

I'm using the jQuery datepicker where I have two textboxes (start date / end date). The user clicks in a respective textbox and the calendar shows up. That is OK.

What I need to do is when the user say, clicks in the start date textbox and picks a date. I need an onblur event to be triggered then.

Where do I set that onblur event for the calendar control after a date has been selected? I tried in the actual textbox but that's not right because that happens before an actual date is picked from the calendar control.

+2  A: 

I think you want the onselect event...

$('.selector').datepicker({
   onSelect: function(dateText, inst) { ... }
});
macca1
macca1, thank you for the response. May I ask a follow up for clarity, please? Where would I put that code so that it fires after a date has been selected? I tried just putting it inside my script tags but it goes off right when the page loads when I do that.
d3020
Yes, you can do this way.But if you still want to use onblur() event then I can suggest that for each date text field set selected date as data to text field element and in onblur() event check that data is changed or not from previous date. if not just return otherwise process your script
Pokuri
If I'm understanding what you're saying though. The question still remains for me as to how to get the date selected onblur() or onSelect of the calendar control. Just to clarify, the user can pick whatever date they want, but when they do I need to then check if that date is greater than today. That is why the onblur or onSelect needs to be fired after the date is selected. Does that make sense? Thanks.
d3020
@d3020 The onSelect is an option that you pass when you first add the datepicker to your element. You add it where you say .datepicker() on your element (probably in your document.ready).Also, if you only want them to pick a future date, you can restrict that: http://jqueryui.com/demos/datepicker/#option-minDate
macca1
Got the onSelect in place. I took a look at that link. It was not apparent to me initially what I'd use to restrict the start date value to be greater than today. I actually need to a couple of things with it including that. Like, make sure end date is greater than start date selected. Then once there valid dates calculate the week difference between the dates. I'd actually pay someone to help me knock this out.
d3020
What I meant by that more specifically is. If you or someone is willing to write up an example of the things I need. I'd pay them for their time.
d3020
In case it might be helpful to someone else reading this. To restrict the datepicker to use only future dates / the onSelect. You can do what macca1 mentioned above and then before the onSelect line add - minDate:'-0d',
d3020