Link to home
Start Free TrialLog in
Avatar of Jason C. Levine
Jason C. LevineFlag for United States of America

asked on

Disable keyboard entry on date field. Force use of calendar popup

Hi folks,

Is it possible to disable people from attempting to type dates into a HTML field and instead just make them use the javascript calendar popup?
Avatar of Cornelia Yoder
Cornelia Yoder
Flag of United States of America image

How about just removing the "HTML field" where you don't want them to enter anything, and just leave the calendar?
You could try some of the following:


<!-- This way, whenever the field gains focus, it automatically loses focus  -->
<input type="text" id="date" onfocus="this.blur();" />
 
<!-- This way, the user cannot type anything -->
<input type="text" id="date" onkeypress="return false;" />

Open in new window

Avatar of KMusatoff
KMusatoff

readonly
ASKER CERTIFIED SOLUTION
Avatar of KMusatoff
KMusatoff

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 Jason C. Levine

ASKER

So declaring a field as readonly will still allow the javascript date-picker to write the value chosen into the field?
"So declaring a field as readonly will still allow the javascript date-picker to write the value chosen into the field?"

Yes... as javascript is probably using element.value = ''; and "readonly" blocks user input only
Alrighty.  Will test and report back tomorrow night.

Thanks to all who have submitted to this point.  I really appreciate your taking the time to assist me.
Setting the field to readdonly worked.  I was under the impression that the field would not accept any data if I used that attribute.  Happy to be wrong.
Nice and easy.  My favorite kind of solution.