Hi, there are some ways to do this, for example:
- give a function to the onkeypress event:
<edit ... onkeypress="Validate();" ...>
(don't explicitly mention the event parameter in the function call and
also don't use return)
- in the Validate function, if the last typed key is not a digit, you
can delete it; or show an alert, etc.
If you need more help just tell me...
Thanks,
Teo.
On Aug 16, 11:14 am, valdus <a.va...@gmail.com> wrote:
I want to only allow numbers 0-9 to be entered into an edit box in a
desktop gadget.
In "normal" JavaScript this is quite easy to accomplish (for input
type text) by creating an event function triggered by the onkeypress
event. The function can check the event.keyCode, if it is a wanted
keyCode the function returns true and the letter/number will appear in
the text box, if it returns false the key event will not be taken into
account.
Example:
___________________________________
function Validate(event)
{
var bRes = false;
if ((event.keyCode >= 48) && (event.keyCode <= 57)) //0-9
{
bRes = true;
}
return bRes;
}
[....]
<input type="text" onkeypress="return Validate(event)">
___________________________________
Now this text box will only accept numbers 0-9.
This works fine when designing a google gadget for my iGoogle page.
BUT when designing a desktop gadget for my Google desktop sidebar it
seems like this has no effect.
How can I accomplish the same function for an <edit .....>?