-1

having this as intial code

<input type="date" class="closed_road_permit_expiry_date" min="2000-01-01" max="9999-01-31" name="closed_road_permit_expiry_date[]" value="value="2000-01-31" />

i tried doing this

<input type="date" class="closed_road_permit_expiry_date" min="2000-01-01" max="9999-01-31" name="closed_road_permit_expiry_date[]" id="currentDate" value=getCurrentDate()/>

  function getCurrentDate() {
        document.getElementById("currentDate").valueAsDate = new Date()
    }
rickyProgrammer
  • 1,177
  • 4
  • 27
  • 63
  • Possible duplicate of [HTML5 Input Type Date -- Default Value to Today?](http://stackoverflow.com/questions/6982692/html5-input-type-date-default-value-to-today) – A. L May 09 '17 at 07:03

3 Answers3

1

run getCurrentDate() function on window.onload not with value of the input

function getCurrentDate() {
  document.getElementById("currentDate").valueAsDate = new Date()
}
window.onload = function() {
  getCurrentDate()
}
<input type="date" class="closed_road_permit_expiry_date" min="2000-01-01" max="9999-01-31" name="closed_road_permit_expiry_date[]" id="currentDate" />
prasanth
  • 22,145
  • 4
  • 29
  • 53
1

You cna run an IIFE to populate the field with the current data

(function getCurrentDate() {
  return document.getElementById('currentDate').valueAsDate = new Date();

}())
<input type="date" class="closed_road_permit_expiry_date" min="2000-01-01" max="9999-01-31" name="closed_road_permit_expiry_date[]" id="currentDate" />
brk
  • 48,835
  • 10
  • 56
  • 78
0

Try this:

    function getCurrentDate() {
       var date = new Date();
       var day = date.getDate();
       var month = date.getMonth() + 1;
       var year = date.getFullYear();
       var datestr = day + "/" + month + "/" + year;
       document.getElementById("currentDate").value = datestr;
    }

    $(document).ready(function(){
       getCurrentDate();
    });
suhaim
  • 314
  • 2
  • 7