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
jQueryHTML

Avatar of undefined
Last Comment
jxbma

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
OmniUnlimited

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Rob

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
jxbma

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
ASKER
jxbma

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
OmniUnlimited

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Rob

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
ASKER
jxbma

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
ASKER
jxbma

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.