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?
Initialize datepicker using date format and set date -
$( ".selector" ).datepicker({ dateFormat: 'yy-mm-dd'}) $( ".selector" ).datepicker( "setDate" , new Date())
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-altFormathttp://jqueryui.com/demos/datepicker/#option-defaultDate
Assuming you are using datepicker from jQueryUI, you can directly set its value right after its initialization:
$('#id').datepicker(); $('#id').datepicker('setDate', new Date);
Source: https://habr.com/ru/post/1381337/More articles:jQuery ui 1.7.3 datepicker set selected date + 3 days - jqueryWhy is Eclipse incorrectly finding spelling errors in Ruby comments? - eclipseUnable to change date format for given date - jquery datepicker - jqueryWhere can I find a list of C keywords (and / or C ++) covering K & R1 / 2, C89-C1X and their origin? - c ++Does open source JavaScript work? - javascriptSending a SOAP Message Using C # Help - c #FlashDevelop Debugger Problem - debuggingMATLAB Callback Error ResizeFcn - matlabSerialize XmlDocument and send via HTTPWebRequest - c #FlashDevelop Haxe (Flash) debugger - debuggingAll Articles