3

I have a asp:textbox , how can i set its minimum date to today using javascript:

With C# I am doing it like this and it works fine..but I have to do it using Js/Jquery

DateTime date = DateTime.Today.Date;
            String today = date.ToString("yyyy-MM-dd");

            tourStartDate.Attributes["min"] =today;
<asp:TextBox Width="95%" ID="tourStartDate" runat="server" TextMode="Date" onchange="SetDate()"></asp:TextBox></td>

2 Answers2

1

On Code Behind C#:

tourStartDate.Attributes["max"] = DateTime.Now.ToString("yyyy-MM-dd");

VB.net:

tourStartDate.Attributes("max") = Now.ToString("yyyy-MM-dd")
Seb33300
  • 6,949
  • 2
  • 38
  • 55
lrturbo
  • 11
  • 2
0

you need to put the ClientIdMode = static in the server control to get the static Id.

<asp:TextBox Width="95%" ID="tourStartDate" ClientIdMode = "static" runat="server" TextMode="Date" onchange="SetDate()"></asp:TextBox>

Jquery: Set today in attribute.

$("#tourStartDate").attr("min", (new Date()));

EDIT:

Can you try <input type="date" min="2015-07-01" max="2015-10-20">

JQuery:

  $("#tourStartDate").attr("min", (new Date()).toISOString().substring(0,10));

Make sure your doc type is html ( for HTML 5 controls)

EDIT2 :

JavaScript :

 document.getElementById('tourStartDate').setAttribute('min', (new Date()).toISOString().substring(0,10));
sudhAnsu63
  • 5,740
  • 4
  • 38
  • 50