Reputation: 13
I want to select the startDate from this field: @Html.EditorFor(model => model.TimePeriod.StartDate, new { htmlAttributes = new { @class = "form-control datepicker", @id="StartDate",@onchange="addDates()" } }) @Html.ValidationMessageFor(model => model.TimePeriod.StartDate, "", new { @class = "text-danger" })
Here I want to autopopulate that start date here
<td>
@Html.EditorFor(model => model.DailyRegister.Date, new { htmlAttributes = new { @class = "form-control", required = "required", @id = "date1" } })
@Html.ValidationMessageFor(model => model.DailyRegister.Date, "", new { @class = "text-danger" })
<script>
function addDates() {
document.getElementById("date1").value = document.getElementById("StartDate");
}
</script>
</td>
Running above code gives this result
Upvotes: 0
Views: 544
Reputation: 66
It might be a silly question, but have you tried getting the value of the start date field instead?
document.getElementById("date1").value = document.getElementById("StartDate").value;
Depending on when you call the addDates()
function you might need an event listener as well.
Upvotes: 0