user3453256
user3453256

Reputation: 79

How to Set Min Date as Default Value in Jquery Datepicker

How to set minimum date (today's date) as default value in Jquery datepicker?

Upvotes: 0

Views: 1556

Answers (2)

user3453256
user3453256

Reputation: 79

I've been happy to solve my issues using stackoverflow. Just now, I could solve an issue by checking http://jqueryui.com/datepicker and other sources (including separate posts here) and thought of sharing what I came up with here.

If you want to use datepicker for date selection, setting minimum date (date today) as the default value, here's what you need to do:

In your document's head portion, place this code:

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.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({ minDate: 0});   
var $datepicker = $( "#datepicker" );
$datepicker.datepicker();
$datepicker.datepicker('setDate', new Date());
});
</script>

Then, in your document's body, place this code:

<p>Date:<input type="text" id="datepicker" name="name_of_your_form"></p> 

I hope this helps. Have a great day!:)

Upvotes: 1

Felix
Felix

Reputation: 38112

You can set the minDate value to 0:

$('#datepicker').datepicker({minDate: 0});

Upvotes: 0

Related Questions