How can I alter key.charCode value ?

J

jh3an

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 !
 
V

VK

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;">
 
J

jh3an

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!!
 
V

VK

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/homepages/PaulGor/screen_e.htm
 
T

Thomas 'PointedEars' Lahn

VK said:
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
 
V

VK

[...] Moreover keyCode is a key _code_, not a string value, so not
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.




:)
 
T

Thomas 'PointedEars' Lahn

VK said:
[...] 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top