Answers for "set default today date in html input type date"

1

html input date default today

<!-- HTML -->
<input type="date" class="today">

<script>
  // JQuery
  $(document).ready( function() {
    $('.today').val(getToday());
  });
  
  function getToday(){
	const local = new Date();
    local.setMinutes(local.getMinutes() - local.getTimezoneOffset());
	return local.toJSON().slice(0,10);
  }
</script>
Posted by: Guest on September-03-2021
0

input date default value html

<!-- HTML -->
<input type="date" id="theDate">

<script>
  // JQuery
  $(document).ready( function() {
    $('#theDate').val(new Date().toDateInputValue());
  });
  
  // Pure JS
  document.getElementById('theDate').value = new Date().toDateInputValue();
  
  
  // Timezone support
  Date.prototype.toDateInputValue = (function() {
    var local = new Date(this);
    local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
    return local.toJSON().slice(0,10);
  });
</script>
Posted by: Guest on June-17-2021

Code answers related to "set default today date in html input type date"

Browse Popular Code Answers by Language