Solved

I need an onBlur event for  some kind of container to run a validation

Posted on 2007-11-30
7
273 Views
Last Modified: 2013-11-19
I have two sets of  radio buttons in a div. One of the option from each is "protect with password".  If the user selected the "password" option in any of these sets, I want to call an onBlur (with the function to enter password) but only once when they leave the div event if possible.  The problem is that only form objects support onBlur event. I use ajax to update my db so I really don't want to call ajax every time someone clicks the radio buttons.
any help is much appreciated
0
Comment
Question by:JoeUS
  • 4
  • 3
7 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20384082
JoeUS,

What do you mean leave the "div event"?  As you pointed out that element (and other non-form elements) does not have an onblur event.  The reason is it doesn't have a focus event either.  So how to you see firing this?  What interaction by the user on the page should trigger this?  We need to find something along those lines to have a chance at finding a "substitute" for the onblur event.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 

Author Comment

by:JoeUS
ID: 20384587
div event was a typo. Sorry for that.
What I am doing right now is I use check boxes and  check for change at onBlur for each of them. I call ajax if anything changed and also request password if there was none set yet. I also call a confirm for the password and if validation fails on them, then move focus back to the proper object accordingly. Now, focus works quite differently in FF than in IE. This is why I would like to call for password, validation and ajax after I am done with the radios or check boxes.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20387072
I don't really understand what you mean.  What is the problem now and is it just browser related?

What needs focus?  When should that happen?  Keep in mind it should be related to an event or script.  You mentioned password, radios, etc but which element has focus and where should the focus go?  What works and when does it fail?  Maybe the explanation above just needs to be reworded or it might just be that it is soo late but it just seems unclear.

If I understand you right you may want to put focus back on some element.  If that is true then you will need a global variable to keep track of where the focus "was."  If I am right and you need script as an example then I can provide it.  This is just a guess though. :)

bol
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JoeUS
ID: 20421073
"If I understand you right you may want to put focus back on some element.  If that is true then you will need a global variable to keep track of where the focus "was.""

Yes it seems like I will need a global to track the focus, but not only to put focus back on some objects but to call some functions. What I want to do is to reduce the number of calls I make back to the server with updates (asynchronous). Ideally I would know, which object  I had the focus on onBlur and make the call accordingly. Unfortunately, I do not know how to track the focus effectively to tell, which object it was on or is explicitly.
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
ID: 20424616
I have reread the comments and info here but I just don't have details to make a specific suggestion for you.  All the things you mentioned in the last comment are just too general for me to know how to suggest you implement a "global" variable.

I can tell you what I mean by that and maybe that is enough.  In the section of your html where you have the script (hopefully the head part of your page) you would declare the variables.  They would not be in a function, etc so they will be "global" and last as long as the page is there.  A simple example of this would be ...

<script type="text/javascript">
var w = null;

That is one I have used for popup windows before.  I end up assigning the new window to w so I can later tell if it exists, is closed, etc.

If you need help using this idea then please provide info.  There is no "canned" way to do what you want and it needs to be "made" for your page and situation.  That doesn't mean it can't be done or the code is complex but just means there isn't one answer.  Let me know if you have a question about this or anything I have said.

bol
0
 

Author Comment

by:JoeUS
ID: 20472119
Thank you b0lsc0tt

This short discussion did help me to figure out what to do about minimizing callbacks to the server. First of all, I decided to fire the ajax for (only) the db updates at on click for the radios and onblur for the other elements. I also use JS to take care of the object updates in the current html. I fire ajax when the objects were correctly updated, so to keep them in sink with the db. I also make sure that the objects are initiated and the values are being reloaded on page load. It does work and the user experience is great! No IE page refresh on every clicks and coughs.

Thanks again for the help
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20472657
Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question