How to get List of possible options on choice variable field?

Zod
Giga Guru

HI,

I have a select box variable and 'remove' some options via a catalog client script on load. 

Now I need to be possible to list the remaining "possible" options via a catalog client script.

How to?

Was was hoping it works this way ... 

 

var values = [];

var sel = g_form.getElement('<variablename>');

for (var i=0, n=sel.options.length;i<n;i++) {

gs.info(sel.options[i].value);

}

.. but this seems not to work.Type Error ...  "sel is undefined" ... 

Any idea?! Thank you! 

14 REPLIES 14

Noor Mohammad1
Kilo Guru

hi Zod,

i can see there is syntax error in for statement where n is not defined anywhere.

Thanks,

S Noor Mohammad

 

Adi26
Tera Expert

Try 

var values = [];

var sel = g_form.getElement('<variablename>');

for (var i=0, n=sel.options.length;i<n;i++)

{

//gs.info(sel.options[i].value);

g_form.addInfoMessage(sel.options[i].value);

}

 

 

Brian Lancaster
Tera Sage

As soon as I try you script I get an error message just trying to save it the object "gs" should not be used in a client script.  gs is only available server side.

Brian Lancaster
Tera Sage

I just tried this in my PDI and it worked fine.  Also note that even though you are using remove option this script will still show all option as it is looking at the element so remove option just hides the option that you removed from the end user so the system does not display it.  I'm not sure there is a way to get what option are left after doing remove option other then just taking a look at the available options when the form loads to do you validation that the options have been removed.  Otherwise I do not know why you would need this.

function onLoad() {
    //Type appropriate comment here, and begin script below
    var values = [];

    var sel = g_form.getElement('a');

    for (var i = 0, n = sel.options.length; i < n; i++) {

        values.push(sel.options[i].value);

    }
	alert (values);
}