How to get the select box length in catalog client script

Shilpi Sharma2
Tera Contributor

HI All,

 

How to get the length of Select box option in catalog client script.

 

var sel = g_form.getControl('from_role');

alert(sel.options.length); giving 0 but it has multiple options.

2 REPLIES 2

Maik Skoddow
Tera Patron
Tera Patron

Hi

the short form is

alert(g_form.getElement('from_role').options.length);

The long form with looping through the values is:

var values = [];
var sel    = g_form.getElement('from_role');

for (var i = 0, n = sel.options.length; i < n; i++) {
   values.push(sel.options[i].value);
}

alert (values.length);

Kind regards
Maik

Hi Mailk,

 

Thanks for replying.

while using short form in catalog client script it is giving error

alert(g_form.getElement('from_role').options.length);

Cannot read properties of undefined (reading 'options')