How to get the select box length in catalog client script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 09:29 PM
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.
Labels:
- Labels:
-
Incident Management
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 09:37 PM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 11:54 PM
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')