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 ?
Posted
Updated 20-Sep-13 5:37am
v2

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:

HTML
<html>
   <head>
      <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.preventDefault();
               eventInstance.returnValue = false;
               return false;
            } //if
         } //filterDigits
      --></script>
   </head>
<body>

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

</body>
</html>


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

—SA
 
Share this answer
 
v2
Comments
V.Lorz 20-Sep-13 14:48pm    
5-ed
Sergey Alexandrovich Kryukov 20-Sep-13 15:04pm    
Thank you.
—SA
Sergey's solution is what you need in this case, but take also a look at this JQuery plugin here http://code.google.com/p/jquery-ui-plugins/wiki/TextInput[^] 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