It's not a secret anymore!*
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
Author

Focussing the html:errors

Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 117
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.
Lz.
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() {
<logic:messagesPresent>
var errorsDiv = document.getElementById("errors");
errorsDiv.scrollIntoView();
</logic:messagesPresent>
}

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


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Focussing the html:errors
 
Similar Threads
Is there any way to bring the a Vertical Scroll Bars of the Scroll Pane at the Bottom by default???
Focussing the validation errors
Auto Scroll List/Scroll Pane
Searching the Cattle Drive
Scrollpane