How to get all the choice values in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2015 04:17 AM
Hi,
I am trying to get all the choice option values in a client script to verify whether the choice field has a particular choice option in it,if not I want to create that option dynamically.
Could someone suggest me,whether we have any method to get the list of choice values in script.
Thanks in advance......
Thanks,
Anusha.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2015 07:34 AM
Hi Anusha,
You can try this client script by changing <choicefield> to the name of your choice field.
var values = [];
var sel = g_form.getElement('<choicefield>');
for (var i=0, n=sel.options.length;i<n;i++) {
if (sel.options[i].value) values.push(sel.options[i].value);
}
alert(values.join(","));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2015 10:11 PM
Thank you Brad, it was helpful for me.
Thanks.
Anusha.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2015 02:19 AM
You can also achieve this by the below piece of script
var field = gr.getElement('os');
var choices = field.getChoices();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2020 07:13 AM
getControl() wont work for the portal though. And I think it is not a good idea to play around with the HTML elements as g_form.getControl() does. I did it like Naveen demonstrated below and sent the values over to the client by a 'g_scratchpad' value using a display business rule.