-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
  • 331,213
  • 40
  • 305
  • 339
Micha
  • 167
  • 2
  • 8

2 Answers2

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

<script type="text/javascript">
  document.getElementById('currentdate').value = Date();
</script>
Shrinivas Pai
  • 7,491
  • 4
  • 29
  • 56
0

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

<input type="date" id="currentdate">
Jens
  • 67,715
  • 15
  • 98
  • 113