Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

When a user selects startDate and endDate, I want start date to be displayed in other text box

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading