|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionWhen the same page returned from the server, scroll to previous focus element on the page. Example: If selecting a value from the dropdown placed way below on the page refresh the page, by default first field will receive the focus or scroll position set to Zero. It forces the user to scroll down to the previous position and lot of frustration. With simple hidden fields, we can come back to same position and set the focus on same field or next field. This will allow the user to continue from the place where they left off.
Add Two Hidden fields under the FORM tag.
<input type="hidden" name = "previousElement">
<input type="hidden" name = "previousScrollPosition">
When you submit the page, you need to call those two javascripts. You can add those javascript function to onchange or onblur or onclick events and finaly submit the page to server. When you render the ASP or JSP page, you need to take both previousScrollPosition, previousElement value from the Request object and populate both the hidden fields. You need to make sure that form fields available in the FORM before calling or using the javascript. If you have multiple fields with same name, then you need to send the index of the field to the server and get the field list using document.getElementsbyName("elementName") function and loop through them to select correct index and set the focus.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||