Quiero seleccionar la fecha de inicio de este campo: @Html.EditorFor(model => model.TimePeriod.StartDate, new { htmlAttributes = new { @class = "form-control datepicker", @id="StartDate",@onchange= "addDates()" } }) @Html.ValidationMessageFor(modelo => modelo.TimePeriod.StartDate, "", new { @class = "text-danger" })
Aquí quiero autocompletar esa fecha de inicio aquí
<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>Puede ser una pregunta tonta, pero ¿ha intentado obtener el valor del campo de fecha de inicio en su lugar?
document.getElementById("date1").value = document.getElementById("StartDate").value;
Dependiendo de cuándo llame a la función addDates() , es posible que también necesite un detector de eventos.