Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have input text box for date. I am using JQuery Date picker. 
I want to set and render the current date in my text box when page loads as default.

I could not able to do it. This is my code.  Its not working. 

Please look at and help me out.

What I have tried:

<pre><label for="dateSelection">Date:</label>
<span style="background-color: antiquewhite; padding-top: 3.6px; padding-bottom: 3.6px;">
<input type="text" id="dtID" name="dateSelection" placeholder="mm/dd/yyyy" ng-model="txtDate" required />
<span class="glyphicon glyphicon-calendar" style="padding-right: 3.6px;"></span>
</span>

   
    $(document).ready(function () {
        $('#dtID').datepicker({
            changeMonth: true,
            changeYear: true,
            showAnim: 'slideDown',
            duration: 'fast',
            dateFormat: 'mm/dd/yy',
            onSelect: function (date) {
                $scope.txtDate = date;
                $scope.$apply();
            }
        }).setDate(new Date());
    });
Posted
Updated 11-Aug-17 5:42am
Comments
[no name] 11-Aug-17 11:11am    
I changed the code. and now its working

$(document).ready(function () {
$('#dtID').datepicker({
changeMonth: true,
changeYear: true,
showAnim: 'slideDown',
duration: 'fast',
dateFormat: 'mm/dd/yy',
onSelect: function (date) {
$scope.txtDate = date;
$scope.$apply();
}
}).datepicker("setDate", new Date());
});
ZurdoDev 11-Aug-17 11:17am    
Please post this as a solution so that this no longer shows as an unanswered question.
[no name] 11-Aug-17 11:42am    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900