1

I have a date input box like this:

<input type="date" id="start_date" name="start_date" class="text_search" />

This displays the date box up to anywhere in the past and future date. Past date is fine but I don't want to show the future date. For example if today's date is May 31, 2013, user can only choose the date upto May 31, 2013. How can I do that?

pynovice
  • 7,424
  • 25
  • 69
  • 109
  • 1
    may be by setting its min and max attributes... – BaSha May 31 '13 at 09:34
  • But I want today's date to be dynamic so I assume I have to use javascript to calculate the today's date. – pynovice May 31 '13 at 09:35
  • cant u set max attribute with today's date? – BaSha May 31 '13 at 09:36
  • possible duplicate of [HTML5 Input Type Date -- Default Value to Today?](http://stackoverflow.com/questions/6982692/html5-input-type-date-default-value-to-today) – Jukka K. Korpela May 31 '13 at 10:46
  • Apart from the relatively trivial issue that you would use the `max` attribute to set the last date, this is a duplicate of a question that asks how to make the current date the default in `input type=date`. – Jukka K. Korpela May 31 '13 at 10:47
  • Use the `max`-Attribute. See: http://www.w3.org/TR/html-markup/input.date.html for more information – sirius May 31 '13 at 09:35
  • But I want today's date to be dynamic so I assume I have to use javascript to calculate the today's date. – pynovice May 31 '13 at 09:36
  • See: http://stackoverflow.com/questions/1531093/how-to-get-current-date-in-javascript – sirius May 31 '13 at 09:38

2 Answers2

2

Use the max attribute as in <input type="date" name="bday" max="1979-12-31">. You can use javascript to set this attribute to today or set it on the server side

neelsg
  • 4,802
  • 5
  • 34
  • 58
0

are you using any jquery ui plugin ? if yes then use following code,

$(function() {
    $("#start_date").datepicker({maxDate: '+0d'});
});
Baby Groot
  • 4,637
  • 39
  • 52
  • 71
  • I first used HTML5 which didn't work in firefox so I ended up using Jquery UI datepicker and your solution works. Thanks mate. – pynovice Jun 03 '13 at 05:19