How do I clear the select box values

poornima2
Mega Expert

I would like to clear a select box of all values without knowing their values.

We have two select boxes called service provider and model.For example if i select "Verizon" within the service provider then the available models appears in the model select box type(for example,8830,8820,Other...).

We have an another Yes/No type field(prior).
If i select "Yes" within this field,then the two select boxes(service provider,model) becomes -- None--
but left the other values there.I'm looking for a way to clear a select box of all values.

I tried setValue,removeOprtion and i tried the following script.

var pri = g_form.getValue('prior');
if(pri == 'Yes')
{
g_form.setValue('model',' ');
var option = ' ' ;
g_form.setValue('Other',option);
}

Thanks...

4 REPLIES 4

Ruth_Porter
Kilo Explorer

Hi there,

I have just tried this and

g_form.setValue('field_name', '') ;

seems to work and so I cannot see why what you have done has not.

Regards, Ruth


If you want to remove the entries from the select entriely:

g_form.getControl('category').options.length = 0;


CapaJC
ServiceNow Employee
ServiceNow Employee

Nice one. Just added to Client Scripts wiki


The following script is working,

g_form.removeOption('model',8820);
g_form.removeOption('model',8310);
g_form.removeOption('model',8800);
g_form.removeOption('model',8830);

Here model - Name of the select box
8820,8310... - Values within the select box.