Clear date picker using jquery

I am setting into a form a date picker, all is fine, but after i click submit i want the date picker to empty out using jquery, but setting its val to "" isnt working

<!-- #region txtDateTime -->

<p class="text textSizeStandard title">@LH.GetText(LH.SystemComponent.TheSystem, "lblSystemClientManagement_DateTime")</p>

@Html.EditorFor(model => model.DateTime, new { @class = "", @id = "txtDateTime" })

    // #region formNewUserClear

    function formNewRecordClear() {



    // #endregion

The other three work fine when called, but #txtDateTime doesnt

Are you sure you have an element with that ID on the page?

1 Like

Just checked the source and this is how the above outputs onto the page

<p class="text textSizeStandard title">Date</p>
<input class="text-box single-line" data-val="true" data-val-date="The field DateTime must be a date." id="DateTime" name="DateTime" type="date" value="" />

And yes I can see the id is actually set to DateTime and not txtDateTime, would that be my issue

Yes it is, cheers Pullo, your question was the answer :slight_smile:

1 Like

Rather than not use it at all, looked for a work around and this below worked perfectly, for others to see -

@Html.EditorFor(model => model.DateTime, new { htmlAttributes = new { @id = "txtDateTime" } })

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.