Scrolling Cart Script for a particular catalog item

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2016 11:57 AM
Hi am trying this script for my catalog item that I got from the user community and I keep getting an error. Can someone take a look please?
Here is the link where I got the code from: Scrolling Cart for Service Request - Oslova Networks
Thank you,
Karen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 05:09 AM
Hi Karen,
Please replace the line 21 with below code
catch(errr){adder = null}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 05:23 AM
I updated line 21 with your change and now more errors. See below for the full code and the errors. I made lines 21 and 31 bolded so you would know which ones they were.
function onLoad() {}
var adder;
var cartContent;
function onLoad()
{
try{
adder = gel('adder');
adder.style.position = "relative";
}
catch(errr){adder = null}
try{
cartContent = gel('sc_cart_contents');
cartContent.style.position = "relative";
}catch(errr){cartContent = null};
window.onscroll = function(){
try{
var y = 12;
if (typeof window.pageYOffset != 'undefined')
y = window.pageYOffset;
else if(typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0)
y = document.documentElement.scrollTop;
else if(typeof document.body.scrollTop != 'undefined')
y = document.body.scrollTop;
if(y > 60){
if(adder != null) {adder.style.top = y - 60 + 'px'; //alert('adder: '+ adder.style.top );
}
if(cartContent != null) {cartContent.style.top = y - 60 + 'px'; //alert('cartcintent: '+ cartContent.style.top )
}
}else{
if(adder != null) {adder.style.top = 0 + 'px';}
if(cartContent != null) {cartContent.style.top = 0 + 'px';}
}
}catch(err){
if(adder != null) {adder.style.top = 0 ;}
if(cartContent != null) {cartContent.style.top = 0 ;}
}
};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2016 10:00 PM
Hi Karen,
Please remove function onLoad() {} from the very first line. and keep the code same as I provided last time.
I hope this helps.Please mark correct/helpful based on impact

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2016 04:27 AM
Good morning Amlan Pal,
It's still not working. I removed the function onLoad() {},
Still getting the error @ line 29 stating that 'errr' is already defined. Line 19 and 29 says i have missing semicolons, IF I add the semicolons back it will say that I have unnecessary semicolons. I am not understanding why this is happening.
Just so you know we are currently using the Eureka version of ServiceNow (not sure if that is making a difference or not)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2016 05:18 AM
var adder;
var cartContent;
function onLoad()
{
try
{
adder = gel('adder');
adder.style.position = "relative";
}
catch(e)
{
adder = '';
}
try
{
cartContent = gel('sc_cart_contents');
cartContent.style.position = "relative";
}
catch(e)
{
cartContent = '';
}
window.onscroll = function()
{
try
{
var y = 12;
if (typeof window.pageYOffset != 'undefined')
y = window.pageYOffset;
else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0)
y = document.documentElement.scrollTop;
else if (typeof document.body.scrollTop != 'undefined')
y = document.body.scrollTop;
if (y > 60)
{
if (adder != '')
adder.style.top = y - 60 + 'px';
if (cartContent != '')
cartContent.style.top = y - 60 + 'px';
}
else
{
if (adder != '')
adder.style.top = 0 + 'px';
if (cartContent != '')
cartContent.style.top = 0 + 'px';
}
}
catch(e)
{
if (adder != '')
adder.style.top = 0;
if (cartContent != '')
cartContent.style.top = 0;
}
}
}