The moose likes Struts and the fly likes Focussing the html:errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Focussing the html:errors" Watch "Focussing the html:errors" New topic

Focussing the html:errors

Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 128
My application is on Struts, I have <html:errors/> tag at the bottom of my screen. My question is on validating the page, the vertical scroll bar should scroll to the bottom so that the errors can be viewed instead of the user scrolling down. Please let me know how this functionality can achieved.

Thanks for your help in advance.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You can do this using a combination of the <logic:messagesPresent> tag and JavaScript.

Surround your <html:errors/> tag with a <div></div> tag pair and assign the <div> an id so that you can find it with JavaScript.

In the on load event of the <body> tag, call a JavaScript function. In that function, surround the statements with a <logic:messagesPresent> tag pair so that they will only be executed if there are error messages. body of the function will consist of code to find the <div> containing the <html:errors> tag and then performing a scrollIntoView() method.

Something like this:

function init() {
var errorsDiv = document.getElementById("errors");

[b}note:[/]This solution will work with Microsoft IE V6, but may not work with other browsers. You'll have to research this.

Consultant, Sima Solutions
I agree. Here's the link:
subject: Focussing the html:errors
It's not a secret anymore!