-1

I have a problem. I want to change the date in the input field to the current date. Here is my code:

<input type="date" id="datum currentdate">
$(document).ready( function() {
    var now = new Date();
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
    $('#currentdate').val(today);
});

But this doesn't work. I have included jQuery. Does anyone know a solution for this problem?

Rory McCrossan
  • 306,214
  • 37
  • 269
  • 303
Micha
  • 77
  • 1
  • 5

2 Answers2

1
<input id="currentdate" name="date">

<script type="text/javascript">
  document.getElementById('currentdate').value = Date();
</script>
Shrinivas Pai
  • 6,765
  • 3
  • 24
  • 54
0

the id for your input field must be currentdate nor datum currentdate

<input type="date" id="currentdate">
Jens
  • 60,806
  • 15
  • 81
  • 95