0

I have daterangepicker from here You can see the javascrpt and css in: http://jsfiddle.net/CUMFw/

I have try to show set default date from this solution(jQuery-UI datepicker default date & How do I pre-populate a jQuery Datepicker textbox with today's date?) but still not work.

this my partially experiment php code:

<script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.1.custom.min.js"></script>
<link rel="stylesheet" href="css/ui.daterangepicker.css" type="text/css" />
<link rel="stylesheet" href="css/redmond/jquery-ui-1.7.1.custom.css" type="text/css"title="ui-theme" />
<script type="text/javascript">
$(function(){ 
     $('#tgl').daterangepicker({
        defaultDate: new Date(),
        arrows:true,
        onChange: function(){
           $('#frmDate').submit()
        },
     });
});
</script>
<?php 
$dates = explode("-",$_POST[tgl] );
$date1=  date("Y-m-d", strtotime($dates[0]));
if ($dates[0] == $_POST[tgl]){
    $date2 = $date1;
    echo $date2;
}
else{
$date2=  date("Y-m-d", strtotime($dates[1]));}
?>
<form id="frmDate" action="http://localhost/job/uadmin.php?page=absensi" method="post">
<input id="tgl" name="tgl" type="text" class="field"  value="<?php echo $_POST[tgl]; ?>"/>
</form>

Please help me out from my problem thanks.

Community
  • 1
  • 1

2 Answers2

0

Two things I'd try. First, make sure you have a link to jQuery above your script block. Use either Google's or a local copy:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

If that doesn't work, next try replacing all instances of $ in your Javascript code with jQuery:

jQuery(function(){ 
 jQuery('#tgl').daterangepicker({
    defaultDate: new Date(),
    arrows:true,
    onChange: function(){
       jQuery('#frmDate').submit()
    },
 });
});

This can help avoid conflicts with other libraries that also use $ as a variable.

musical_coder
  • 3,886
  • 3
  • 15
  • 18
  • hi musical_coder, thanks for your respons. it turns out I already have jquery.min.js and jquery.UI.min.js. I have edit my question. And then i have change `$` with `JQuery` but still not work. – Mohamad Damba Putrabangga Aug 20 '13 at 05:41
  • Try going back to basics then. Replace the inside of the jQuery block with this: `jQuery('#tgl').daterangepicker({arrows: true, dateFormat: 'M d, yy'});`, which I borrowed from the source code of demo page for Date Range Picker. When you do that, does it at least show the range picker, minus today's date? – musical_coder Aug 20 '13 at 05:59
  • Hi Mohamad- did either answer work for you? If so, please click the checkmark on one of them to accept it. Otherwise, please let us know if we can help you further. – musical_coder Aug 25 '13 at 18:02
0

I did not understand the question properly. instead of defaultDate try setDate. As I know there is no onChange event try onSelect method.

$('#tgl').daterangepicker({
    setDate: new Date(),//changed defaultDate to setDate.
    arrows:true,
    onSelect: function(){
       $('#frmDate').submit()
    }//removed comma here
 });
Viraths
  • 840
  • 1
  • 13
  • 23
  • Hi Viraths,thanks for your respons. Previous code,i have try with `setDate`. But still not work. and then i try with `defaultDate` but still the same. I just want to set the current date as the default early in my datepicker. So that when I open this page I can filter the data according to the current date. – Mohamad Damba Putrabangga Aug 20 '13 at 05:54
  • Did you try onSelect method instead of onChange – Viraths Aug 20 '13 at 06:00