Click here to Skip to main content
15,885,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
I have a text-box. Where I have assigned a calender using jquery css. But my requirement is when I shall run the project, the current date will show in the text-box by default.
I am using the following code.

<script type="text/javascript">
		function myFunction() {
			var a = new Date();
			document.getElementById("datepicker").value = Date();
		}
</script>
<input type="text" id="datepicker">
Posted

1 solution

you can specify default date when you initialize datepicker, for example
JavaScript
<script type="text/javascript">
$(function() {               
    $("#datepicker" ).datepicker({
        dateFormat : 'dd-mm-yy',
        defaultDate: new Date()
    });
   $("#datepicker").datepicker('setDate', new Date());
});
</script>
 
Share this answer
 
v3
Comments
Member 11710169 26-May-15 9:02am    
It is not working......
DamithSL 26-May-15 9:18am    
check my updated code, above will select current date as default value in datepicker and also set the textbox value with current date

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