Scrolling Cart Script for a particular catalog item

Cupcake
Mega Guru

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

find_real_file.png

Thank you,

Karen

18 REPLIES 18

Hi Karen,



Please replace the line 21 with below code



catch(errr){adder = null}




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.



find_real_file.png


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 ;}



      }



};



}


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


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)



find_real_file.png


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;


              }


      }


}