with asp.net, how can pass javascript date into input with type datetime.
input tag:
<input asp-for="EndingDate" id="enddate" class="form-control input-sm" />
and the attempt to send javascript date to the input value:
const d = new Date("2015-03-25");
$('#enddate').val(d.toJSON());
Did you try below.
const d = new Date("2015-03-25");
$('#enddate').val(d);
This will assign date time to asp.net text filed. But no-masking and calendar. If the field have calendar then you need to call calendar initiate method after this.
$("#enddate").datepicker();
The form post should work as it is.
Try this
let endDate = new Date().toISOString().substr(0, 10); //Get Date part
$('#enddate').attr('value',endDate);
If your EndingDate
is type of DateTime, it will generate the input with type="datetime-local"
.
Change your code below:
var isoStr = new Date("2015-03-25").toISOString();
$('#enddate').val(isoStr.substring(0,isoStr.length-1));
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.