[jQuery] Revert focus on duplicate check error.

[jQuery] Revert focus on duplicate check error.


I have a form with multiple rows. On each row, the first field is a
key field; that is, it can't be duplicated on any other row. The
comparison is working, as I currently have an alert() if there's a
duplicate. What I want to happen is if there is a duplicate, focus
the field the user just changed. For some reason, the next field is
always focused. My guess is, I focus the previous field, and the
change() finishes running and re-focuses to the next field. Is there
any way to prevent this? Here's my code:
    $('input.Code').change(function(e) {
        $(this).parent().parent().removeClass('dontsort'); // Remove
'dontsort' from the row.
        retVal = checkForDupes(this); // Check for duplicates.
        if( retVal == true ) {
            $(this).parent().trigger('click');
            $(this).focus();
            return false;
        } else {
            addBlankRecord();
        }
    });
I trigger a click, because when a field is clicked, the background
color is changed. I have a click function set up on all TD tags (each
TD tag has an INPUT tag inside it). I don't think I need the focus
(or the return false) after the trigger, but since the trigger wasn't
working, I thought I'd try something else. I had tried an
e.preventDefault(), but that didn't work either. addBlankRecord() is
not getting called, so I know retVal is true. Can anyone help?