jQuery datePicker

This is a quick note, not really a tutorial since this stuff is really trivial to setup. I use the jQuery datePicker plugin by Kelvin Luck.

jQuery date picker

The HTML / Smarty code:

{config_load file="$config_file"}
<script type="text/javascript" src="{$baseUrl}/js/date.js"></script>
<script type="text/javascript" src="{$baseUrl}/js/date_{$language}.js"></script>
<!--[if IE]><script type="text/javascript" src="{$baseUrl}/js/jquery.bgiframe.js"></script><![endif]-->
<script type="text/javascript" src="{$baseUrl}/js/jquery.datePicker.js"></script>
<link rel="stylesheet" href="{$designDir}/css/datePicker.css" type="text/css" />
{literal}
<script type="text/javascript">
Date.format = 'yyyy-mm-dd';
$(function(){ $('input.date-pick').datePicker({startDate:'1996-01-01'}); });
</script>
{/literal}

Note the dependency on Jörn Zaefferer’s date library.

In this case we have German as an alternative language, hence the date_{$language}.js above. We begin with looping through all input fields with the class date-pick and apply the date picker logic to them.

Using Date.format = ‘yyyy-mm-dd’ will make sure that we get the date in this format in the PHP $_POST array, this format makes any further conversions unnecessary in order to do direct date comparisons in MySql. This works for example:

$sql = "SELECT * FROM products WHERE some_datetime > {$_POST['start_date']}";

Note the use of startDate:’1996-01-01′, we want to be able to select dates in the past with this date as the limit.

The default CSS looks like crap IMO, the above screenshot uses this CSS instead.

  • Digg
  • del.icio.us
  • blogmarks
  • Reddit
  • Simpy
  • StumbleUpon
  • Technorati
  • description
  • Ma.gnolia
  • Slashdot
  • Sphinn
  • Spurl

Related Posts

Sponsored links

Stock Market For Beginners
Hypnotherapy London

Tags: , ,

Posts linking to this article:

[web] 連結分享
css. 9 top css essential skills that every web designer should learn; print watermarks with css; css sprites2 - it's javascript time; urban grey side menu; easy equal columns with css; pixel precision with diagnostic css ...

Subscribe with Google Reader