I have an input textfield in my html file:
<p>From Date: <input type="text" id="datepicker"></p>
I assign, using jQuery a uidatepicker to this textfield:
$( "#datepicker" ).datepicker({
dateFormat: 'dd-mm-yy',
maxDate: new Date(theDate.getFullYear(), theDate.getMonth(), theDate.getDate())
});
Once the user selects a date, they press the “Go” button. I need to obtain the date entered into the textfield via the datepicker. I have tried:
$("#go").click(function(e){
alert($("#datepicker").text()); //doesn't work
}
but it doesn’t work….
EDIT:
Ok so after messing about the following works:
alert($("#datepicker").datepicker("getDate"));
But the output is:
Tue Aug 09 2011 00:00:00 GMT+0100 (BST)
I want it just as dd-mm-yy. I have already set the dateFormat for my datepicker, so I’m not sure how to get the correct output….
Replace
.text()with.val()to be able to read the values placed into the textfield of the datepicker.