Hi,
My guess (untested, don't know about interplay with alert) is if you
through in a defer[1], it'll work:
else {
(function(){
$(this).focus();
}).defer();
alert("invalid number");
return false;
}
...but that the user experience won't be great for a variety of
reasons (not least because the focus will go to the new field, then
revert to the previous one; and separately, alerts are not great user
experience).
Can I suggest instead, that you validate fields without getting in the
user's way (interfering with their navigation), providing a visual
clue that the field value is not okay (perhaps a red border around the
field, an icon next to it, etc.), and if the user tries to send the
information anyway, at that point using a more intrusive mechanism
(perhaps an alert) to tell them that there are issues and to deal with
the highlighted fields.
[1] http://prototypejs.org/api/function/defer
HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available
On Jun 1, 8:32 pm, 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);
> if(IsNumber(numericField,true)){
> return true;
> }
> else {
> $(this).focus();
> alert("invalid number");
> return false;
> }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---