Workflow and ServiceDesk Community

 View Only

Mimicking Form Anchors with the scrollto() Method 

Oct 01, 2015 01:22 PM

Original article is posted here.

In response to another forum post, I came up with a method of mimicking the functionality of an html anchor tag on a Workflow form.  What this does, functionally, is scrolls a form to a specific position.

(see attached gif)

So this one is pretty simple – you basically set a Control Id on an element that we will call the “anchor” element, and then reference that element and get the position.  Here’s the javascript set to an onclick event in the demo.

var labeltwo = document.getElementById('Label2');
window.scrollTo(0, parseInt(labeltwo.style.top));

This is repeated for each label in the demo.  At the bottom, to get back to the top, we simply use this onclick javascript:

window.scrollTo(0, 0);

Easy enough!

As a side note – “window.scrollTo()” sets the working context to “window”, being the form itself.  If you need to jump around inside a specific scrolling element (such as a ListSelect component), set the context properly to do so.  As an example, with a ListSelect component with a Control Id of “ListSelect1”, we would get the element first:

var list1 = document.getElementById('ListSelect1');

Then, set the context to only the ListSelect element:

list1.scrollTo(0, 0);

I've attached a demo project for reference.

Statistics
0 Favorited
0 Views
2 Files
0 Shares
2 Downloads
Attachment(s)
package file
Element Anchor Demo.package   58 KB   1 version
Uploaded - Mar 11, 2020
gif file
scrollto.gif   55 KB   1 version
Uploaded - Feb 25, 2020

Tags and Keywords

Related Entries and Links

No Related Resource entered.