I am trying to create an HTML form that will be used to send data to the backend in C#.
Below is the form which consists of 2 fields: FROMTIME and TOTIME. I need to make sure that the user inputs the values in the format of HH:MM
but this is not feasible without validation.
I have tried using input type="time"
but this does not allow me to serialise the data and send them to the backend. I am using $("#editForm").serialize
or $("#editForm").serializeObject
or $("#editForm").serializeArray
but the data is empty because the serialisation does not include the Time data. Any ideas please?
Could you please let me know, is there an easy way to force the user to input hour and minutes in the format of HH:MM
? Many thanks!
<form id="editForm">
<table>
<tr>
<th>From Time: </th>
<td style="background-color:white;">
<input type="text" id="FROMTIME" placeholder="HH:MM" name="FROMTIME" value="@Model.FROMTIME" asp-for="FROMTIME" required form="editForm" />
</td>
</tr>
<tr>
<th>To Time: </th>
<td style="background-color:white;">
<input type="text" id="TOTIME" placeholder="HH:MM" name="TOTIME" value="@Model.TOTIME" asp-for="TOTIME" required form="editForm" />
</td>
</tr>
</table>
</form>