How to disable or grey out 'Add to Cart' button once shopping cart reaches 5 or more items?

Harriet K
Mega Guru

Hi Dev community!

I am trying to disable or grey out the 'Add to Cart' button in a service catalog item once the shopping cart total reaches >= 5 items.  May I get assistance what is the syntax to disable the 'Add to Cart' button, please?

I have tried the following and they all do not work:

1. 

document.getElementById('sc_add_to_cart_button').style.display='none';

2. 

var addtocart = document.getElementById('add_to_cart_button');
addtocart.style.display='none';

3. 

$('oi_add_to_cart_button').disabled=true;

My PDI is a New York version.

Thanks in advance!

Best regards,
Harriet

 

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

Use below script to hide cart.

Make sure that you do GlideRecord in script include and call script include from your client script.

  var user_id =   g_user.userID;


  var sccart = new GlideRecord('sc_cart_item');


  sccart.addQuery('cart.user',user_id);


  sccart.query();



  var count = 0;


  while(sccart.next()){


  count = count+parseInt(sccart.quantity);


  }

if(count >5 ){


  var cart = document.getElementById('order_and_cart_v2');



  cart.style.display='none';


}

 

 

Regards,

Sachin

View solution in original post

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

Use below script to hide cart.

Make sure that you do GlideRecord in script include and call script include from your client script.

  var user_id =   g_user.userID;


  var sccart = new GlideRecord('sc_cart_item');


  sccart.addQuery('cart.user',user_id);


  sccart.query();



  var count = 0;


  while(sccart.next()){


  count = count+parseInt(sccart.quantity);


  }

if(count >5 ){


  var cart = document.getElementById('order_and_cart_v2');



  cart.style.display='none';


}

 

 

Regards,

Sachin

Thank you, Sachin! It did not work for me, but I think I'm not able to see the true end result since ours behaves differently due to maybe some kind of business rules. Anyway, I appreciate your help and response!

hi,

i have the same requirement how can i call this script include into client please, and what should i modify this line

  var cart = document.getElementById('order_and_cart_v2');

should i put yhe name of the button in getElementById