[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set Focus on a textbox after validation

Posted on 2009-02-20
2
Medium Priority
?
1,234 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:bcarlis
2 Comments
 
LVL 3

Accepted Solution

by:
KMusatoff earned 500 total points
ID: 23695294
You can use onBlur
0
 
LVL 9

Expert Comment

by:brunoguimaraes
ID: 23695598
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question