Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


onblur problem when attempting to set focus

onblur problem when attempting to set focus

onblur problem when attempting to set focus

I have a simple form with a number of text fields, check boxes and radius buttons.

The text fields need to be validated for data type format (phone, date, time, etc.). I use the onblur behavior to check entered value, validate and proceed accordingly.

Now, image fields PHONE1 and PHONE2, they are both next to once another. the onblur calls for a script which in turn makes an AJAX call to a PHP script. The script checks and validates data and returns a response ... All of this is working except that when the data is not valid, the script sets focus to the field based on its ID but some how, the same script is called by the onblur of the 2nd field as the first regains focus.

In other words, user presses TAB from PHONE1 - routines validates, fails and set focus to PHONE1. The browser, naturally attempts to place cursor in PHONE2 and it appears that the .focus() command triggers the same routine but for PHONE2.

I would not have a problem if not because I am using a "shared" layer where to display message returned by PHP script with a detailed explanation of why data may have failed.

How do I skip the onblur action for PHONE2 if PHONE1 validation had failed?

The good thing about not knowing is the opportunity to learn - Yours truly, 2008.

RE: onblur problem when attempting to set focus

either you have to debug when the script fires. or let it fire but conditionalise the execution of the main part of the script by some variable that you set/unset depending on whether you are in the process of validating another field etc.

or you can use the jquery .off and .on methods to remove the events.

RE: onblur problem when attempting to set focus

I think the question is how you are setting the focus back to Phone1 when it fails,

Because it sounds like Phone2 is getting focus, and immediately loosing it, triggering the blurr event, and thus the function. Perhaps instead of returning focus to the previous field, simply highlighting it with a colored border or something similar would be a better choice. Thus avoiding the focus-blurr cycle that can be very hard to get out off.

Phil AKA Vacunita
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close