469,271 Members | 1,586 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

How can I alter key.charCode value ?

How are you ? :)
This code works on Internet Explorer:

function(event){
event.keyCode = 'a';
}

So, No matter what you typed in the textbox or textarea, you would get
'a'.

However, above the code does not work on Firefox or Safari.(even
though I use event.charCode instead of event.keyCode).

Please give me your advice !
Mar 22 '08 #1
6 2030
VK
On Mar 22, 10:52 pm, jh3an <jh3...@gmail.comwrote:
This code works on Internet Explorer:

function(event){
event.keyCode = 'a';

}
That is your allusion. One cannot refactor user-initiated events, that
would allow so-called "interface stealing" and possible security
break. IE is no different here, at least IE6/IE7. Moreover keyCode is
a key _code_, not a string value, so not
event.keyCode = 'a';
but
event.keyCode = 65;
then but it doesn't matter because it will not work for the reason I
just explained.

If you want to make a virtual keyboard, then catch onkeydown event for
the input element, cancel this event and update element value with
your own input:

<input type="text" name="txt"
onkeydown="this.value+='a';return false;">
Mar 22 '08 #2
Is there another way to do it ?
If I want to type in the middle of string, the result always goes to
end of string always.
That's why I tried to find a way to change key.charCode value.

HELP!!
Mar 22 '08 #3
VK
On Mar 22, 11:20 pm, jh3an <jh3...@gmail.comwrote:
Is there another way to do it ?
No - unless on browsers with defective security I am not aware of or
unless it will be considered one day just fine to refactor user-
initiated events (I deeply hope it will never happen).
If I want to type in the middle of string, the result always goes to
end of string always.
On virtual keyboards the regular way to do it is by creating ranges:
one from the beginning to the current cursor position and other from
the current cursor position to the end. Combining it with the previous
tip, you can get what you want. See for instance Paul Gorodyansky's
virtual Russian keyboard:
http://ourworld.compuserve.com/homep...r/screen_e.htm
That's why I tried to find a way to change key.charCode value.

HELP!!
Mar 22 '08 #4
VK wrote:
On Mar 22, 10:52 pm, jh3an <jh3...@gmail.comwrote:
>This code works on Internet Explorer:

function(event){
event.keyCode = 'a';

}

That is your allusion.
Probably you meant "illusion", because "allusion" does not make sense here.
One cannot refactor user-initiated events,
You have yet to understand what refactoring actually is.
[...] Moreover keyCode is a key _code_, not a string value, so not
event.keyCode = 'a';
but
event.keyCode = 65;
then but it doesn't matter because it will not work for the reason I
just explained.
The latter works as supposed in MSHTML for the `keypress' event. You could
have performed a test at least before giving more bad advice.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Mar 23 '08 #5
VK
[...] Moreover keyCode is a key _code_, not a string value, so not
event.keyCode = 'a';
but
event.keyCode = 65;
then but it doesn't matter because it will not work for the reason I
just explained.

The latter works as supposed in MSHTML for the `keypress' event. You could
have performed a test at least before giving more bad advice.
It does? Well, why am I not surprised...

Now you see how I missed you: any high level specialist like myself
needs a helper to clean up after him such as better wording or lesser
important details: so the specialist would not waste his valuable time
on that.


:-)
Mar 23 '08 #6
VK wrote:
>>[...] Moreover keyCode is a key _code_, not a string value, so not
event.keyCode = 'a';
but
event.keyCode = 65;
then but it doesn't matter because it will not work for the reason I
just explained.
The latter works as supposed in MSHTML for the `keypress' event. You could
have performed a test at least before giving more bad advice.

It does? Well, why am I not surprised...

Now you see how I missed you: any high level specialist like myself
needs a helper to clean up after him such as better wording or lesser
important details: so the specialist would not waste his valuable time
on that.
The only problem here is that *you* are the beginner posing as an expert,
and that other people I would consider real experts repeatedly have to waste
their time to correct your bad advice.
:-)
A smiley does not make any nonsense that you keep on posting any better.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Mar 23 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by M Simpson | last post: by
4 posts views Thread by Thomas Christensen | last post: by
3 posts views Thread by Kimi | last post: by
1 post views Thread by brian.newman | last post: by
7 posts views Thread by Serge Rielau | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.