Reputation: 16320
I am using a calender plug-in and I want to populate the current date into a text field. How can I do this using jquery?
Upvotes: 6
Views: 44104
Reputation: 42093
You can get current date in JavaScript:
var now = new Date();
If you are using jQuery DatePicker you can apply it on any textfield like this:
$('input.youTextFieldClass').datepicker({ dateFormat: 'mm/dd/yy',
changeMonth: true,
changeYear: true,
yearRange: '-70:+10',
constrainInput: false,
duration: '',
gotoCurrent: true});
If you want to set current date in textfields as page load:
$("input.youTextFieldClass").datepicker('setDate', new Date());
Upvotes: 12
Reputation: 388316
You can find the sample here.
<input type="text" id="datepicker">
$( "#datepicker" ).datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date());
Upvotes: 2