Friday, 22 February 2013

Getting dropdown options in Javascript


At times, I 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 this helps!

Feel free to drop your valuable comments below.

No comments:

Post a Comment

Urdhva Tech Pvt. Ltd. Powered by Blogger.

Urdhva Tech

My photo
SugarCRM Consultants Contact us at Skype : urdhvatech

Search This Blog

Stay connected Socially


Total Pageviews

Popular Posts