try this
$(function() { $("#datepicker").datepicker({
maxDate: '0'});
});
This will set the maxDate to +0 days from the current date (i.e. today). Here is the reference
Question
I have the following code which allow users to add order details. And I'm using the datapicker jQuery to display a calendar for dates. For example, the order date field, I want to prevent users from choosing a future date. How can I do that? My code is as follows: edit.ctp:
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1950:2020',
dateFormat: "yy-mm-dd"
});
$("#datepicker2").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1950:2020',
dateFormat: "yy-mm-dd"
});
});
</script>
</head>
<?php
$usertype = $this->SESSION->read('User.usertype');
?>
<body>
<div class="orders form">
<?php echo $this->Form->create('Order'); ?>
<fieldset>
<legend><?php echo __('Edit Order Details'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('invoice_number', array('required' => false));
echo $this->Form->input('order_date', array('required' => false, 'id' => 'datepicker', 'type' => 'text'));
echo $this->Form->input('payment_type', array('required' => false, 'options' => array('Cash' => 'Cash', 'EFTPOS' => 'EFTPOS', 'CC' => 'CC', 'Cheque' => 'Cheque', 'PayPal' => 'PayPal'), 'empty' => '(choose one)'));
echo $this->Form->input('order_type', array('required' => false, 'options' => array('Email' => 'Email', 'Telephone' => 'Telephone', 'Web' => 'Web'), 'empty' => '(choose one)'));
echo $this->Form->input('date_promised', array('required' => false, 'id' => 'datepicker2', 'type' => 'text'));
echo $this->Form->input('order_description', array('required' => false));
echo $this->Form->input('order_comments', array('required' => false));
echo $this->Form->input('order_total', array('required' => false));
echo $this->Form->input('amount_deposited', array('required' => false));
echo $this->Form->input('balance_due', array('required' => false));
/* echo $this->Form->input('customers_id', array('required'=>false));
echo $this->Form->input('employees_id', array('required'=>false));
*/
echo $this->Form->input('customers_id', array('label' => 'Customer Name', 'options' => $customers, 'label' => 'Customer Name', 'required' => false));
echo $this->Form->input('employees_id', array('label' => 'Employee name', 'options' => $employees, 'label' => 'Employee name', 'required' => false));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div
</body>
</html>
Can someone please help?
Solution
try this
$(function() { $("#datepicker").datepicker({
maxDate: '0'});
});
This will set the maxDate to +0 days from the current date (i.e. today). Here is the reference
OTHER TIPS
fiddle: http://jsfiddle.net/pvXzb/
jquery:
$("#datepicker").datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1950:2020',
dateFormat: "yy-mm-dd",
maxDate: 0
});