Google脚本-表单-文本字段的实时更新 [英] Google Script - Form - live update for a text field
问题描述
我的客户有很多联系人. 我创建了一个带有滚动列表的表单,以便选择一个联系人.问题是滚动列表太长. 有没有一种方法(如果可以,怎么办?)让我的客户开始输入联系人姓名的首字母,因此字段区域"(或其他)会自动填写对应的联系人姓名? 预先感谢您的帮助. 亲切的问候,
My client has a huge list of contacts. I created a form with a scrolling list, in order to select a contact. The issue is that the scrolling list is too long. Is there a way (and if so, how?) for my client to start typing the first letters of a contact name, so the 'field area' (or other) fills in automatically the correspondant contact name? Thank you in advance for your help. Kind regards,
推荐答案
您可以使用以下javascript加载选择:
You can load the select with this javascript:
function updateSelect(vA)
{
var select = document.getElementById("sel1");//or whatever you select id is
select.options.length = 0;
for(var i=0;i<vA.length;i++)
{
select.options[i] = new Option(vA[i],vA[i]);
}
}
html选择元素:
<select id="sel1">
<option value="" selected></option>
</select>
我经常在页面加载时加载选择内容,例如:
I often load selects when the page loads with something like this:
$(function(){
google.script.run
.withSuccessHandler(updateSelect)
.getSelectOptions();//a gs function which passes an array to updateSelect via the success handler
});
这样,我可以使用电子表格存储所需的值.在您的情况下,您可能想按字母顺序过滤它们.而且,您可能希望传递getSelectOptioptions()函数或任何称为参数的参数来确定如何过滤列表.
That way I can use a spreadsheet to store the values that I want. In your case you may want to filter them alphabetically perhaps. And you might want to pass the getSelectOptioptions() function or whatever you call it a parameter to determine how to filter the list.
这篇关于Google脚本-表单-文本字段的实时更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!