Show/Hide Form Section

rsanon
Tera Contributor

Does anyone know how to Hide/Show a form section based on a field. I attempted to follow the example below from the wiki, but it did not work for me. See attached.

function onChange(control, oldValue, newValue, isLoading) {
//this example was run on a form divided into sections (Change form)
// and hid a section when the "state" field was changed
var sections = g_form.getSections();
if (newValue == '2') {
sections[1].style.display = 'none';
} else {
sections[1].style.display = 'block';
}
}
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#Form_Information_Methods

15 REPLIES 15

sailesh1
Tera Contributor

You can even use this

function onLoad() {
//Type appropriate comment here, and begin script below
g_form.setSectionDisplay("xx",false);
g_form.setSectionDisplay("yy",false);
g_form.setSectionDisplay("bb",false);
g_form.setSectionDisplay("zz",false);
}

 

Similar script can be used for OnChange as well