To Hide "Add to Cart " & "Order Now " Button using client script

deeps
Giga Contributor

Hi ,

        I am currently using HELSINKI version .

As per my requirement I am using Multiple choice type variable which has two options "greater than 5" and " less than 5" for the first option "greater than 5" I have to show all the related following questions and for other options i.e less than 5 I have to hide those questions .Which is working fine .

But when less than 5 option is selected I have to hide "Add to Cart" and "Order Now " button which will restrict user from submitting order .

Tried the client script by using below but nothing seems to work, and the questions which needs to be hide are not hiding any more after using below.

                                                          $('order').hide();

                                                        $('cart').hide();

                                                          document.getElementById('order_now').hide();

I have used following client script:

function onChange(control, oldValue, newValue, isLoading) {
    //Type appropriate comment here, and begin script below
   

if (isLoading || newValue == '') {
          //   alert("Returing");
                return;
}
var request = g_form.getValue('application_details_user');
if(request == 'Greater than 5')
  {
    alert("greater than 5 option is selected");
    g_form.clearValue('Greater than 5');
  }
else(request == 'Less than 5')
          {
  alert("less than 5 option is selected");
      g_form.clearValue('Less than 5');
    //$('order').hide();
    //$('cart').hide();
    // document.getElementById('order_now').hide();
    // document.getElementById('add_to_cart_button').style.display='none';
    }
}

Thanks In Advance

Deepti

1 ACCEPTED SOLUTION

Hi Deepti,



To hide entire cart and frames, I used the following catalog client script:



function onLoad() {


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


  cart.style.display='none';


}



We are on Helsinki as well.



Maria


View solution in original post

8 REPLIES 8

Mihir Mohanta
Kilo Sage

Use Below code in client script.





  var ordernow = document.getElementById('order_now');


  ordernow.style.display='none';


  var addtocart = document.getElementById('add_to_cart_button');


  addtocart.style.display='none';





Thanks,


Mihir


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Deepti,



The below code should work.



$('oi_order_now_button').hide();


$('oi_add_to_cart_button').hide();



P.S : It's not a best practice. Reference


http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#Avoid_DOM_Manipulation&gsc.t...


Hello Pradeep ,


                                                Thanks it worked for me.


                                               


                                              Please let me know how to get this value or   where to find it 'oi_order_now_button' ?


                                           


                                                $('oi_order_now_button').hide();



Thanks,


Deepti


Hi   ,                              


I am currently using HELSINKI version .


As per my requirement I am using Multiple choice type variable which has two options "greater than 5" and " less than 5" for the first option "greater than 5" I have to show all the related following questions and for other options i.e less than 5 I have to hide those questions . .



When Greater than 5 option is selected I have to refresh my screen to see " Order Now   Button" is there something I need to add in below code?



Earlier my requirement was to hide 'Order Now Button' and 'Add to cart Button' , when "Less than 5 " is selected but now I have to hide Entire Frames including "Shopping cart" and "Empty" value "   show below for particular catalog


                                   


I have used below client script :



function onChange(control, oldValue, newValue, isLoading) {
    //Type appropriate comment here, and begin script below
   


if (isLoading || newValue == '') {
          //   alert("Returing");
                return;
}
var request = g_form.getValue('application_details_user1');
if(request == 'Greater than 5')
  {
  // alert("greater than 5 option is selected");
    //g_form.clearValue('Greater than 5');
  }
else(request == 'Less than 5')
          {
  //alert("less than 5 option is selected");
    // g_form.clearValue('Less than 5');
      gel('qty').firstElementChild.childNodes[0].style.display = 'none';
      sc_delivery_time_label_cell.hide();
      sc_delivery_time_cell.hide();
      quantity_label_span.hide();
      quantity.hide();
      $('oi_order_now_button').hide();
                        $('oi_add_to_cart_button').hide();
    // shopping.hide();


    }
}



Which gives me below output :


find_real_file.png


I don't require those frames too.



And Please let me know how to find the values or rather where to find it ?



$('oi_order_now_button').hide();


                        $('oi_add_to_cart_button').hide();



Any help will be appreciable .



Thanks Deepti