开发者

how to add picklist value and text correctly using javascript?

开发者 https://www.devze.com 2023-04-11 03:51 出处:网络
I got and error while add picklist value : \"The picklist value is out of the range.\" myCode : var cityCodes = new Array();

I got and error while add picklist value : "The picklist value is out of the range."

myCode :

    var cityCodes = new Array();
cityCodes['1']='Adana - 322 ';
cityCodes['2']='Adiyaman - 416 ';
cityCodes['3']='Afyonkarahisar - 272 ';
cityCodes['4']='Agri - 472 ';
cityCodes['5']='Aksaray - 382 ';
cityCodes['6']='Amasy开发者_如何学Ca - 358 ';
cityCodes['7']='Ankara - 312 ';
cityCodes['8']='Antalya- 242 ';
cityCodes['9']='Ardahan- 478 ';

    for (var i in cityCodes) {
         crmForm.all.new_faxprefix.AddOption(cityCodes[i],i);
     }


Arrays are zero-index based, you started adding to your array at index 1, check out the following javascript code.

var cityCodes = [];
cityCodes[0]='Adana - 322 ';
cityCodes[1]='Adiyaman - 416 ';
cityCodes[2]='Afyonkarahisar - 272 ';
cityCodes[3]='Agri - 472 ';
cityCodes[4]='Aksaray - 382 ';
cityCodes[5]='Amasya - 358 ';
cityCodes[6]='Ankara - 312 ';
cityCodes[7]='Antalya- 242 ';
cityCodes[8]='Ardahan- 478 ';

for (var i = 0; i < cityCodes.length; i++) {
    crmForm.all.new_faxprefix.options[i] = new Option(cityCodes[i], i);
}

check out this fiddle


The Picklist values actually have to exist in the CRM customizations for the record to save. You can't just add them in script.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号