.focus() from onSubmit

I'm trying to set the focus to a particular Form Input object in a form's Validation Routine.

My validation routine is called from the onSubmit() of the <FORM> tag.  It appears to very briefly give the focus to the correct intput object, but then appears to have the focus changed to the submit button.

Any clues?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

That works fine for me... you should show your validation routine.
HUMMELSAuthor Commented:
Here is the complete HTML.  I've cut it down to the basics


function Validate(TheForm) {
   for (var i=0; i < TheForm.elements.length-1; i++) {
      if (TheForm.elements[i].value.length==0){
         alert("you must fill something in!");
         return false;


<FORM NAME="displayorder" onSubmit="return Validate(this)">
<INPUT TYPE="text" NAME="one" VALUE="ONE">
<INPUT TYPE="text" NAME="two" VALUE="TWO">
<INPUT TYPE="text" NAME="three" VALUE="THREE">
<INPUT TYPE="text" NAME="four" VALUE="FOUR">
<INPUT TYPE="submit">


Well, there's a little misunderstanding in your code:

should be:
for (var i=0; i <= TheForm.elements.length-1; i++)

or better:
for (var i=0; i < TheForm.elements.length; i++)

instead of:
for (var i=0; i < TheForm.elements.length-1; i++)

So, i guess you missed focus on the last field.

Let me know if this is not clear.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

...or, if i missed the point!
HUMMELSAuthor Commented:
In my example, I've got 4 text inputs.  The submit also gets considered as an input object.  That is why I'm doing the TheForm.elements.length-1.  So it will go through all the inputs except the submit button, which is the last one.
Ok, right, my fault. And, feel free to reject my answer.

This said, again, the code is valid.

Maybe you could tell which OS/Browser combination you are trying it on?
Did you try it on a different browser?
Is the page accessible on-line, for a test?
Do you have the complete code with the forms to? : )
Ignore the comment above. I was not awake. Sorry!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

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.