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?
Asked
Active
Viewed 4.4k times
6
-
5what calendar plugin? can you show us the link? – Reigel Gallarde Jan 17 '11 at 05:07
2 Answers
12
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());
-
3Throw a tag name on that selector and it will run faster. Replace `'.youTextFieldClass'` with `'input.youTextFieldClass'`. – chprpipr Jan 17 '11 at 05:13
2
You can find the sample here.
<input type="text" id="datepicker">
$( "#datepicker" ).datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date());

Arun P Johny
- 384,651
- 66
- 527
- 531