views:

635

answers:

1

Given this markup:

// Calendar.html?date=1/2/2003
<script>
  $(function() { 
    $('.inlinedatepicker').datepicker();
  });
</script>
...

<div class="inlinedatepicker" id="calendar"/>

This will display an inline datepicker with very little effort (awesome!). How do I preset the datepicker to the date passed in via the query string?

Note that in this case, I don't have an input box--just a calendar attached to a div.

+2  A: 

This should work, though you may run into locale issues (specifically, M/D/Y vs. D/M/Y).

var date = location.match(/(?:\?|&)date=(\d+\/\d+\/\d+)(&|$)/)[1];
$('.inlinedatepicker').datepicker().datepicker("setDate", new Date(date));
Ben Blank
I'll give it a try. It seems crazy to me that there's not a jquery built-in to get a querystring parameter value without using plugins or complicated code.
Michael Haren
I don't doubt there's a plugin for it somewhere, but the jQuery core contains very little aside from DOM manipulation and Ajax.
Ben Blank
Yeah, I'm beginning to learn that--it's by design.
Michael Haren