Getting dropdown options in Javascript

At times, We have ran into requirement of getting drop down options of a field in Javascript in SugarCRM.

Here is the code that will get you options as an array.

For example, you want to fetch values of case_status_dom, the code will be,

var statusOptions = SUGAR.language.languages.app_list_strings['case_status_dom'];

alert(statusOptions['Closed']); // alert a key and you will have its value

// You can loop through them to create an dropdown in JS itself.

var status_dd = "<select name= 'status' id='status'>";

for(var key in statusOptions){ 
    // Here "key" gives the key of options and "statusOptions[key]" gives the value of it. 
    status_dd += '<option value="'+key+'">'+statusOptions[key]+'</option>';    
}
status_dd +="</select>";

Hope you find this blog post helpful.

Feel free to add comments and queries, that helps us to improve the quality of posts.

You can contact us at info@infotechbuddies.com

Thank you.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *