Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a WebDateChooser textbox which automatically fills up with the current date when the page loads. I can edit this textbox and enter a custom value date. My problem is that after entering a custom date, if i press Enter key and then click outside the textbox, it reverts back to the default date. But this doesn't occur if I click outside the textbox without pressing the Enter key.

What can be the problem ? And is there any way by which i can nullify the effect of pressing the Enter key in the text box ?
Updated 20-Sep-13 5:37am

You cannot prevent pressing any key by the software, quite apparently. :-)

You can make some control ignoring some clicks. For example, this is how to filter out all characters but digits:

      <script type="text/javascript"><!--
         function filterDigits(eventInstance) { 
            eventInstance = eventInstance || window.event;
                key = eventInstance.keyCode || eventInstance.which;
            if ((47 < key) && (key < 58) || key = 45 || key == 8) {
               return true;
            } else {
               if (eventInstance.preventDefault)
               eventInstance.returnValue = false;
               return false;
            } //if
         } //filterDigits

<input type="text" onkeypress="filterDigits(event)"/>


Pay attention that you also have to allow #8 (backspace).

Share this answer
V.Lorz 20-Sep-13 14:48pm    
Sergey Alexandrovich Kryukov 20-Sep-13 15:04pm    
Thank you.
Sergey's solution is what you need in this case, but take also a look at this JQuery plugin here[^] as it could be usefull for future references.

If you need more details on keypresses processing, this link has also some more implementation details: [^].
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900