How to get the index of the selected item in a list box?

大城市里の小女人 提交于 2019-12-05 19:57:49

The other answer doesn't make much sense since Google Apps Script is executed on Google's server, not in your browser and indexOf() is well recognized in GAS.

You should use an array with the elements of you listBox and then using listArray.indexOf(listelement); you'll get the index of the selected item.

example :

//in the UI construction 

var ItemlistArray = ['item1','item2','item3','item4'];// note that this variable definition could be placed outside of the function so it becomes a global variable...
for (n=0,n<ItemlistArray.length;++n){
ListBox.addItem(ItemlistArray[n]
}

//in the Handler function

var item = e.parameter.listBoxName
var ItemlistArray = ['item1','item2','item3','item4'];// if ItemlistArray is global this line can be removed
var index = ItemlistArray.indexOf(item); // if for example the selected item was 'item3', index will be 2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!