MusicLovingIndianGirl
MusicLovingIndianGirl

Reputation: 5947

Clear selection in JQuery DatePicker

I have a Jquery DatePicker control like so.

<asp:TextBox runat="server" ID="txtDate" CssClass="textEntry" MaxLength="12"
                                ClientIDMode="Static" onkeyup="javascript:shouldsubmit=false;" ValidationGroup="vTimeSlot"></asp:TextBox>

The script for the control is as follows

$("#<%= txtDate.ClientID%>").datepicker({
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: "dd-mm-yy",
                    yearRange: '1901:2050',
                    //maxDate: new Date(),
                    showOn: "button",
                    buttonImage: "images/calendar.png",
                    buttonImageOnly: true,
                    showButtonPanel: true,
                    showMonthAfterYear: true,
                    inline: true,
                    altField: "#<%= HiddenDate.ClientID%>",
                altFormat: "dd-mm-yy",
                onSelect: function (dateText, inst) {
                    shouldsubmit = true;
                    javascript: __doPostBack('<%= txtDate.ClientID%>', '');
                },
                onClose: function (dateText, inst) {
                    shouldsubmit = false;
                }
            });

Say for example, I have chosen some date. I want to clear that on click of a button from code behind.

How do I do this?

Upvotes: 0

Views: 304

Answers (2)

Milind Anantwar
Milind Anantwar

Reputation: 82241

use .val('') to assign empty value to textboxes:

$("#<%= txtDate.ClientID%>").val('');

from code behind:

txtDate.Text = ""; or txtDate.Text = string.Empty;

Upvotes: 2

Rituraj ratan
Rituraj ratan

Reputation: 10378

Set value empty to clear datepicker value by .val()

   $(button).on("click",function(){
    $("#<%= txtDate.ClientID%>").val('');
    });

Upvotes: 1

Related Questions