On Jun 2, 5:32 am, molo <[email protected]> wrote:
> I could use some help. I've been looking at this all day and cannot
> come up with a solution
>
> I am using the same routine on these 5 input fields. If I type in a
> character on one of these fields and press enter, it works as expected
> I get an error alert and focus on the field. However if I type in a
> character and tab out of the field I get an alert error but the focus
> is on the next field. I guess the blur event takes it to the next
> field.
>
> Can someone tell me what I need to do to get the focus working
> correctly here
>
> Here is my event related code
>
> Event.observe('oldidratio','change',validateNumberChange);
> Event.observe('cashpershare','change',validateNumberChange);
> Event.observe('proration','change',validateNumberChange);
> Event.observe('newid1ratioentry','change',validateNumberChange);
> Event.observe('newid1fmv','change',validateNumberChange);
>
> Here is the function
>
> function validateNumberChange(){
> var numericField = $F(this);
It's an input field and you already have a reference to it, there is
no need to use the $ function:
var inputValue = this.value;
> if(IsNumber(numericField,true)){
> return true;
> }
> else {
If the condition is true, it has already returned so there is no need
for an else branch. The statements for the false condition just follow
the if block.
> $(this).focus();
The focus method belongs to the input, there is no need to use the $
function:
this.focus();
> alert("invalid number");
That is a really good way to annoy your users (see TJ's post). To get
it to "work", use setTimeout to call the focus method:
var el = this;
window.setTimeout(function(){el.focus()}, 0);
But I don't recommend doing that.
> return false;
Why?
--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---