Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

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

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
JoeUS
Asked:
JoeUS
  • 4
  • 3
1 Solution
 
b0lsc0ttCommented:
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
 
JoeUSAuthor Commented:
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
 
b0lsc0ttCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
JoeUSAuthor Commented:
"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
 
b0lsc0ttCommented:
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
 
JoeUSAuthor Commented:
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
 
b0lsc0ttCommented:
Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now