Click to See Complete Forum and Search --> : Position of cursor when onkeypress ocurrs


fabi
08-01-2003, 07:36 AM
Hello!

Somebody knows as to make the following one:

I have one input text associated to the event onkeypress.

The function of this event is to validate caracter that he is being typed at the moment. Exists a way of I to know where position of text is being typed caracter?

Thanks,

Fabi

Charles
08-01-2003, 08:02 AM
I dont't know of any way to do that but I do know that JavaScript works fast enough that you should be able to just revalidate all of the characters. The user will not know the difference.

fabi
08-01-2003, 08:23 AM
Input imagines one text with the following value: 00.000.000/0000-00.
In the first position alone the entrance of numbers and letter ' P ' is allowed. If the user typed the number above and suddenly he needs to change the first one to caracter for ' P ' the event onkeypress will be validating the entrance of the characters.
I need to have certainty that the user is trying to change the first one to caracter for ' P ' and not them excessively.
How I make I verify this? The value of input is 00,000,000/0000-00 and the value of the event is ' P '.

Charles
08-01-2003, 08:26 AM
You are not at all clear. What exactly do you want the value to look like in the end?

fabi
08-01-2003, 09:05 AM
I will try to explain again.

I made the following code:

function validator(event, myText, tipo) {
if (getObjBrow().isNetscape())
key = String.fromCharCode(event.which);
else
key = String.fromCharCode(event.keyCode);

var isForeign = /P/i;
var isNumeric = /^[0-9]+$/;

if( (isForeign.test(key) && (myText.value == '')) ||
isNumeric.test(key)) {
return true;
} else {
return false;
}
}

This code allows to the digitação of a number or 'P' in the first position and numbers in excessively.

Imagines that the user typed 00.000.000/0000-00 and later field any of the screen was for one.

Before submitting the form the user noticed that it needs to change 00.000.000/0000-00 for P0.000.000/0000-00.

Script that I made is not allowing that it makes this. The using one only obtains to type the 'P' if the field will be clean. I must leave to modify it.