views:

263

answers:

3

Hello,

I can't find how I can set $_GET variables to set manually the date in the date picker. http://jqueryui.com/demos/datepicker/

( example : http://www.something.com/?day=21&month=2&year=2010 )

Is that possible ?

Thanks

+1  A: 

Use the gup function in this link to read the get parameters. Then call the setDate method (error handling omitted):

$(function() {

  $("#Datepicker").datepicker();
  var year = gup("year");
  var day = gup("day");
  var month = gup("month");

  $("#Datepicker").datepicker("setDate", month + "/" + day + "/" + year);

});
kgiannakakis
I really think that only by completing the input the datepicker is auto set.
Mihai Iorga
thank you :) :) is gup secured ? i mean do we have to do any htmlspecialchars() on the variables ?
Tristan
This is a client-side solution. You should test that year, day and month are actually integers using isNaN method, before building the date string. You can also achieve the same thing in PHP, as other users have suggested. To do so you must also generate your javascript code with PHP - you can't use an external script file.
kgiannakakis
+1  A: 

$day = $_GET['day']; $month = $_GET['month']; $year = $_GET['year'];

$date = "'".$day."/".$month."/".$year."'";

<\script>

$.datePicker("setDate",$date);

<\script>

sushil bharwani
thank you :) :)
Tristan
+2  A: 

Simple :)

set minimum date if you want for datepicker:

<?php
    $today = mktime(0,0,0,$_GET['month'],$_GET['day'],$_GET['year']);
?>

<script type="text/javascript">
    var thisday = new Date('<?=(date('Y/m/d', $today);?>');
    $("#YOUR_INPUT").datepicker({minDate: thisday, dateFormat: 'dd/mm/yy'});
</script>

or set automatically from GET variables:

<input type="text" name="YOUR_INPUT" id="YOUR_INPUT" value="<?=$_GET['day'];?>/<?=$_GET['month'];?>/<?=$_GET['year'];?>">

I think this should solve your problem.

Mihai Iorga
thank you :) will try asap
Tristan