I have found a function on Dynamic Drive that does email validation that I am satisfied with. I have 4 email address fields on my form and want to use this function to validate. I use the onblur event to call the function If I only call the function from one field it works perfectly when I test the error state. If I call it from more than 1 field, testing the error state, then it gets stuck in a loop, ie when I click OK it immediately alerts again. The only way out is for me to kill the process. I thought that it may not like me calling the function by the same name or using the same variables. I then created another copy of the function and changed all the variable names. This still causes the problem described above. Here is the function, plus my copy. Can anybody explain to me why this is happening
The reason this is occurring is because as you set focus to the textbox that has an invalid entry, another textbox is losing it's focus, as the textbox that loses its focus also has an invalid entry then the focus is set to it, creating an endless loop. You could create a switch that determines whether the user has changed the focus or you have changed the focus, or just remove the lines .focus() and .select(), and only display the message.