Set Focus on a textbox after validation

Hi,
I have a tabular form that has a textbox column with an onchange="isSortNumber(this);"

If u put a "w" in the first textbox and click on the second textbox it gives the error alert, clears the textbox but then the focus goes to the textbox u had clicked on.

What do I do to get the focus to the cleared textbox that still needs to be corrected.
function isNum(v) {
	return (v.toString() && !/\D/.test(v));
}
function isSortNumber(pthis){
   if (isNum(pthis.value)) return true;
   alert('"'+pthis.value+'" is not a numeric value. Please enter again.');  
   pthis.value='';
   pthis.focus();
 
   return false;
}

Open in new window

LVL 2
BILL CarlisleAPEX DeveloperAsked:
Who is Participating?
 
KMusatoffConnect With a Mentor Commented:
You can use onBlur
0
 
brunoguimaraesCommented:
Try using setTimeout instead.

function isNum(v) {
        return (v.toString() && !/\D/.test(v));
}
function isSortNumber(pthis){
   if (isNum(pthis.value)) return true;
   alert('"'+pthis.value+'" is not a numeric value. Please enter again.');  
   pthis.value='';
   setTimeout("document.forms[0].elements['" + pthis.name + "'].focus();",2);
 
   return false;
}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.