Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping people from writing in text box 2

Status
Not open for further replies.

fischadler

Programmer
May 31, 2002
258
MT
I have a text box with a calendar icon beside it so people can choose a date from the pop up calendar and the date goes into this text box. However, some people insist on typing in the date in the text box and type it incorrectly (ie. Febuary instead of February). How do I stop them from typing into the text box and hence forcing them to use the calendar. I tried disabling the textbox but then the calendar stops working too.
Can I just get the text box to just ignore keystrokes without disabling it?

-Fischadler
 
How about you set the textbox to be of type hidden? It won't show on the page, but it will still be there for the calendar control. If you wanted to show the user the date that they have chosen, then you could modify the calendar control to set the value into a <span> as well as populating the value of the textbox (which would be hidden).

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Jeff's is the best method, however you may also want to consider

Code:
<input type="text" name="t1" readonly="readonly" />
or
Code:
<input type="text" name="t1" onfocus="this.blur();" />



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Thank you both!

Wishing you a Merry Christmas and a prosperous New Year to you and your families.

-Fischadler
 
Actually I used your suggestion because it was the easiest, but I should try the other one too, at least to learn more about how the calendar works (I got the calendar source from Planet Source Code!).

The easy way leads to the Dark Side....LOL!

-Fischadler
 
also, if you use the "readonly" method it may not work in all browsers, and if you use the second (javascript) method it won't work for anyone who has disabled javascript (roughly 10% of users according to one survey).



*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Yes I noticed that. And highlighting the text and pressing the back space key triggers the submit button (on both IE and FireFox) when using the readonly option.

-Fischadler
 
Oh. I see. I must have made some confusion because the site I am working on loads itself when submit is clicked. Since I had refreshed, the back space was doing the same effect.

Good to know though.

-Fischadler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top