You can implement leave event as you are saying with the help of onblur event. Attach onblur event of your second textbox, now when user leaves second textbox, onblur event event will be fired and you can do ehatever you on this event as per your requirement.
see example of onblur event:
Link 1[
^]
Link 2[
^]