So, I have a working version of this here: http://jsfiddle.net/yEmvm/19/
When you click on the company of the first address block and then click on the name it fires the event and says invalid address. I don’t want to fire that event until I cilck on company for the second address block or anywhere outside that first address block. I cannot figure out another event to trigger this on.
This is just an example. This page will contain an unknown number of address blocks from 3 to 99. Also, it will contain many more fields for a full address. The user can keep adding more with a button. However, class and id name structure is consistent.
You should run your code in a timeout, and cancel timer on focus:
Here’s a very basic example: http://jsfiddle.net/U6TRj/3/
Explanation:
Basically, if you’re clicking on an
inputelement while being focused on anotherinput, the browser will first fire theblurevent on the old element, then thefocusevent on the new element.What we’re doing here with the
timeout(no delay required), is pushing the execution of the code down the stack, so that it executes after thefocusevent handler. That way, we can cancel it’s execution from within thefocuscallback.