Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Hide next button in order guide onchange client script

DharaneethaS
Tera Contributor

I need to hide the on change client script based on the variables selected in the order guide describe needs.

I have tried to use this client script and its not working:

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading) return;

  // Find the Next button by its ID
  var nextBtn = document.getElementById("submit");

  if (nextBtn) {
    // Disable the button based on your condition
    if (newValue === 'No') {
      nextBtn.disabled = true;
      nextBtn.style.opacity = '0.5';
      nextBtn.style.pointerEvents = 'none';
    } else {
      nextBtn.disabled = false;
      nextBtn.style.opacity = '1';
      nextBtn.style.pointerEvents = 'auto';
    }
  }
}
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@DharaneethaS 

but why to hide the NEXT button?

If you hide then how will user proceed?

💡 If my response helped, please mark it as correct ✔️ and close the thread 🔒 — this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

when one value is no it should be disabled and not allowed to move forward.if its yes it should allow

Kusal45
Tera Contributor

Hi @DharaneethaS ,

 

Instead of writing a complex scripting to hide "next" button, you can proceed with preventing the user going to step 2(Choose Options) with the help of below simple script.

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var val= g_form.getValue("field_name");
    if (val== "Yes") {
        g_form.addInfoMessage("Message to the user why he is not allowed to step2");
        return false;
    }
 
Please mark as "helpful" if this is useful.
 
Thanks