samobellows
Programmer
Hello all!
here's my basic problem. i have a form validation script that makes sure what the user just entered is a valid entry for that textbox. i have the script running with the onblur event, so that when the user leaves the textbox, it validates the text.
as it stands, the validation is working, but the focus has changed, even if there is an error. what i would like to do is set the focus back to the textbox that the user just left, and select the contents of that textbox, if an error is triggered.
here's a code example:
so, is there a way to set the focus to the last focus? or maybe cancel the onblur event if an error is triggered? my searches of the forums so far have been enlightening as always, but i haven't found a solution.
Thanks for the help!
Samo
here's my basic problem. i have a form validation script that makes sure what the user just entered is a valid entry for that textbox. i have the script running with the onblur event, so that when the user leaves the textbox, it validates the text.
as it stands, the validation is working, but the focus has changed, even if there is an error. what i would like to do is set the focus back to the textbox that the user just left, and select the contents of that textbox, if an error is triggered.
here's a code example:
Code:
var errorID = 0; // global variable.
function formValidation()// this function is called by an onblur event in all of my textboxes
{
validateNumber(); //function sets errorID = 1 if value is not a number
validateLength(); // there are about 10 different things validated like this, each with a different errorID
if(errorID == 0)...; // runs the script, only if there was no error code
if(errorID == 1) ...; // runs the not a number error message
if(errorID == 2) ...; // and so on for each potential errorID.
}
so, is there a way to set the focus to the last focus? or maybe cancel the onblur event if an error is triggered? my searches of the forums so far have been enlightening as always, but i haven't found a solution.
Thanks for the help!
Samo