Make focus on a div

Hey guys,

Today I was working with some form validation kind of thing. My form was about two pages long.

When a user submits some wrong information I want to display some error messages on top the page. And that error messages was in a div. I was not able to focus on that div. Than I tried with a html hidden element but in vain.

Finally after a lot of googling I found the solution i.e.

“Anything which cannot get focus can be forced to get focus by using scrollIntoView() method.”

So have tried with this document.getElementById(‘div’).scrollIntoView();

It works fine in IE and firefox, I have not checked in other browsers.