How to set today date in input type date using Java Script ( JS )

How to set today date in input type date using Java Script ( JS )

                    

<html>
<head>
<title>Codelizar</title>
<script src=”https://code.jquery.com/jquery-3.4.1.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){

// Format is DD/MM/YY

var date_val = new Date();

var month_val = date_val.getMonth()+1;
var day_val = date_val.getDate();

var result = day_val + ‘/’ + ((”+month_val).length<2 ? ‘0’ : ”) + month_val + ‘/’ + ((”+day_val).length<2 ? ‘0’ : ”) + date_val.getFullYear();

$(‘#date_textbox’).val(result);
});
</script>

</head>
<body>
<h1>Set today date in input type date using Java Script ( JS ) </h1>
Today Date is : <input type=”text” id=”date_textbox” value=””>
</body>
</html>

OR you can also use this code —

document.getElementById(‘select_date’).valueAsDate = new Date();

Leave a Reply

Your email address will not be published. Required fields are marked *