Good Day Everyone,
I would like to seek your help in displaying the current date to input type"date" when button is click.
format is like this or mm/dd/yyyy. thank you
$(function() { $('#btncheckout').click(function() { var time = new Date(); $('subdateout').val(time.toDateString()); }); });
<div class="input-group-sm mb-3 row align-middle "> <input type="date" name="subdateout" id="subdateout" class="form-control rounded-0 w3-tiny" max="<?php echo date('Ym-d');?>" value=""> </div> <div class="col-sm-3"> <button type="button" id="btncheckout" class="btn btn-primary btn-sm rounded-0">Check Out</button> </div> </div>
Here's a down and dirty way to get it into the format you want.
var time = new Date(); var datestring = ("0"+(time.getMonth()+1)).slice(-2) + "/" + ( "0" + time.getDate()).slice(-2) + "/" + time.getFullYear() console.log(datestring)
Taken from this amazing collection of date format options. How to format a JavaScript date
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.