Checking focus on an element in interaction with uppercase function

N

Newcomsas

Hello.
I'm trying to solve a little problem with an uppercase function. It
looks like this:

function uppercase()
{
key = window.event.keyCode;
if ((key > 0x60) && (key < 0x7B))
window.event.keyCode = key-0x20;
}

....and it works fine.
I have got an HTML form with many textboxes; until now I performed the
uppercase in all of them.
Now my customer asked me to let the users insert lowcase characters in
just one of them.
I think the best way should be to test the focus on this one
textbox... Fact is, I did not find a satisfactory way to check the
property: a myTextBox.hasFocus does not exist indeed.

Is there anyone who knows how it is possible to do that ? I would like
to be able to change my function more or less in this way:

if (((key > 0x60) && (key < 0x7B)) && (myTextBox.hasFocus==false))
etc.

i thank you in advance for your help,

Newcomsas
 
B

Bart Van der Donck

Newcomsas said:
I'm trying to solve a little problem with an uppercase function. It
looks like this:

function uppercase()
{
key = window.event.keyCode;
if ((key > 0x60) && (key < 0x7B))
window.event.keyCode = key-0x20;

}

...and it works fine.
I have got an HTML form with many textboxes; until now I performed the
uppercase in all of them.
Now my customer asked me to let the users insert lowcase characters in
just one of them.
I think the best way should be to test the focus on this one
textbox... Fact is, I did not find a satisfactory way to check the
property: a myTextBox.hasFocus does not exist indeed.

Is there anyone who knows how it is possible to do that ? I would like
to be able to change my function more or less in this way:

if (((key > 0x60) && (key < 0x7B)) && (myTextBox.hasFocus==false))
etc.

Your strategy is not optimal. I would definitely go for a different
approach. In so far I can see,

<input onKeyUp="this.value = this.value.toUpperCase();">

does exactly the same as your function. Personally I would go for

<input style="text-transform: uppercase;">

but form data arrives then at the server "as typed". It could be
uppercased there at wish.

Obviously the opposite is also possible:

<input onKeyUp="this.value = this.value.toLowerCase();">
<input style="text-transform: lowercase;">

Hope this helps,
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,156
Latest member
KetoBurnSupplement
Top