how to hide field using javascript

shva1991
Kilo Contributor

how to hide field using javascript

4 REPLIES 4

Mihir Mohanta
Kilo Sage

You can use below syntax in client script to hide a field.



g_form.setVisible('fieldName', false);



g_form.setDisplay('fieldName', false);



Please go through below link for your reference.


GlideForm (g form) - ServiceNow Wiki




Thanks,


Mihir




Sharique Azim
Mega Sage

Hi,


Shiva using


g_form.setVisible('field name',false);


or


g_form.setDisplay('field name',false);


you can hide a field.



Tip:


If you are using it on some record producer variable kindly use g_form.setDisplay('variable name',false); .This syntax on the record producer hides the field and also saves the space of the field,so the next variable can come just in its place.



Please also go through below link for your reference.


GlideForm (g form) - ServiceNow Wiki




Regards,


Shariq.


<Hit like and correct answer if it helps>


michal29
Mega Guru

Hello Shiva,



As for pure Javascript, you can:



document.getElementById("ID_OF_YOUR_ELEMENT").style.display = "none";   -> element is not visible and does not take screen space


or


document.getElementById("ID_OF_YOUR_ELEMENT").style.visibility = "hidden";   -> element is not visible and does take screen space



or use jQuery


$(".divIDClass").hide();



Regards,


Michal


Hi,



I would suggest you to do through UI policy



Note:For faster load times, use a UI policy instead of a client script when the only purpose of the script is to set a field to show/hide, read/write, or mandatory/optional.