Skip to content Skip to sidebar Skip to footer

Auto Scrolling In Struts Project On Jsp

i am using struts framework along with jquery and there is button. On click of that button action to save data is called if data is valid else error in top div is shown. But the p

Solution 1:

Your question doesn't really make it clear whether this validation happens client-side or if you're talking 'bout a response from the server, and you haven't shown any code, so I'm not sure where exactly you need to put the following to fit your existing implementation, but anyway you can bring an element into view like this:

document.getElementById("idofyourdivhere").scrollIntoView(true);

The parameter true should align the element to the top of the scrolling area; if you pass false instead it should align with the bottom.

I don't know if there's a jQuery method to do the same thing, but of course you can select the div with jQuery (you might already be doing so to set the error message) and then call the non-jQuery function - the following uses jQuery to set the error message and unhide the div (obviously this assumes it was hidden initially) before bringing it into view the non-jQuery way:

var yourDiv = $("#idofyourdivhere");
yourDiv.html("Your error message here").show();

yourDiv[0].scrollIntoView(true);

Post a Comment for "Auto Scrolling In Struts Project On Jsp"