This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Focussing the html:errors

 
Luke Zechariah
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic