I've got two text boxes on a registration page, one for an individual's email address and the second one for retyping the email address in an attempt to prevent a properly formatted but incorrect email address from being entered into our database.
The problem is this. If I use the 'onchange' in the Retype field to compare the values and it fails, I can't send focus back to the Retype field and allow the user to edit the current value and correct what is probably a minor error. If I want to send focus to other fields, I can. But it will not go back to the Retype field.
If I use the onblur event, then I can get the focus to return to the Retype field. However, if the error is actually in the Email field, then you are locked into the Retype field until you enter a value that matches the Email value, which is incorrect.
My process right now is to
1) use onchange
2) if it fails, blank out the Retype field and let focus go to the next control
Not ideal, but I haven't found a better way.
How do others handle this situation? In case it is helpful, the code I use is below.
if (document.register.email.value != document.register.verifyemail.value)
alert("The 'Retype Email' address does not match the 'Email' address.");