Initialize jQuery-datepicker text box with today's date in yyyy-mm-dd format

I am using jQuery datepicker attached to text input. Is there a datepicker action that can initialize a text field with today's date (yyyy-mm-dd) when the page loads?

+3
source share
3 answers

Initialize datepicker using date format and set date -

$( ".selector" ).datepicker({ dateFormat: 'yy-mm-dd'}) $( ".selector" ).datepicker( "setDate" , new Date()) 
+3
source

You can set the default date to a fixed or relative value:

 // Only necessary if you are sending data using a different format $( ".selector" ).datepicker({ altFormat: 'yy-mm-dd' }); // Initialize to a fixed date $( ".selector" ).datepicker({ defaultDate: '2011-10-20' }); // or to a relative date $( ".selector" ).datepicker({ defaultDate: +7 }); 

http://jqueryui.com/demos/datepicker/#option-altFormat
http://jqueryui.com/demos/datepicker/#option-defaultDate

+1
source

Assuming you are using datepicker from jQueryUI, you can directly set its value right after its initialization:

 $('#id').datepicker(); $('#id').datepicker('setDate', new Date); 
0
source

Source: https://habr.com/ru/post/1381337/


All Articles