Jquery UI : date picker. How to set date in date picker by $_GET

15,561

Solution 1

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);

});

Solution 2

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.

Solution 3

<?php
    $day = $_GET['day'];
    $month = $_GET['month'];
    $year = $_GET['year'];
    $date = "'".$day."/".$month."/".$year."'";
?>

<script>
    $.datePicker("setDate", <?php echo $date; ?>);
</script>
Share:
15,561
sf_tristanb
Author by

sf_tristanb

CTO @ Y-Proximité (Lyon - France) | @sf_tristanb Symfony developper | Personal project : http://www.seek-team.com

Updated on June 16, 2022

Comments