Link to home
Start Free TrialLog in
Avatar of jxbma
jxbmaFlag for United States of America

asked on

Is there a way in jQuery to to set the min/max for an <input> field of type date?

Hi:

I have an HTML5 input date control.

   <input id="StartDate"  type="date">

Open in new window


Is there a way to set the min/max values through jquery?

Thanks,
JohnB
ASKER CERTIFIED SOLUTION
Avatar of OmniUnlimited
OmniUnlimited
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jxbma

ASKER

tagit:

Yikes. I didn't realize that it wasn't universally supported.
We've got this defined a whole bunch of times.
For purposes of impending demo, we'll make sure that we run on Chrome.
If I take the DatePicker, I'll get the min/max for free.

Thanks for tip.
JB
Avatar of jxbma

ASKER

OmnitUnlimitted:

There isn't a way to specify min/max directly through jquery for HTML5 date control?
For demo purposes, we'll use the blur.

Thanks,
JB
By "not supported", tagit is simply referring to the fact that the field won't operate correctly in those browsers.  You will still see a standard text field, and it will still operate like a text field allowing user input and string comparisons through jQuery (like the one I set up.)

You can code min max dates right into the field (although as tagit pointed out, they won't be supported in IE and Firefox), and use jQuery to change those attributes, but it seems the best thing would be to set up a jQuery function to create the behavior you are looking for.
Sounds like re inventing the wheel to me when the date picker from jQuery is available and restricts input to dates as well as a max and min value
Avatar of jxbma

ASKER

I've requested that this question be closed as follows:

Accepted answer: 0 points for jxbma's comment #a39472402
Assisted answer: 250 points for OmniUnlimited's comment #a39472302
Assisted answer: 250 points for tagit's comment #a39472328

for the following reason:

You guys rock.
I've got demo in a day or two, so I'll just blur for now.
I'll switch to datepicker after demo.

Thanks,
JB
Avatar of jxbma

ASKER

You guys rock.
I've got demo in a day or two, so I'll just blur for now.
I'll switch to datepicker after demo.

Thanks,
JB