gpt4 book ai didi

html - 使用 Google App Script 从单独的 Google 表格创建的 HTML 表单中的动态下拉列表中传递选择的值

转载 作者:行者123 更新时间:2023-12-05 06:21:59 24 4
gpt4 key购买 nike

I am unable to Pass the value of a selection from the Dynamic Dropdown List in HTML form created from a another Google Sheet within same file using Google App Script.

我是新手,我制作了 Google 表格来自动化/组织我的日常工作流程以供个人使用。我通过互联网从其他用户的视频/脚本中获取帮助并对其进行编辑以实现我的目标。

我正在为我的一位密友开发一个小型 Google 表格,以便使用应用脚本在 Google 表格中为他的创业公司创建一个客户列表。请帮忙。

function getSelectList() 
{
var sheet = SpreadsheetApp.openById(".......").getSheetByName('Client_List_Dropdown');
var lastRow = sheet.getLastRow();
var myRange = sheet.getRange("A3:A" + lastRow);
var data = myRange.getValues();
Logger.log("Data = " + data);
return data;
};




function openInputDialog_New_ClientContact() {
var html = HtmlService.createHtmlOutputFromFile('Add_ClientContact').setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi()
.showModalDialog(html, 'Add Record');
}




// Add Single Item & Close on Submit
function itemAdd_New(form) {

// Select Sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Add_ClientSheet");

sheet.appendRow([form.Title, form.Full_Name, "=CONCATENATE(INDIRECT(ADDRESS(ROW(),COLUMN()-2)), ,INDIRECT(ADDRESS(ROW(),COLUMN()-1)))", form.mySelectList, form.Designation, form.Email, form.Per_Email, form.Mobile, form.STD_Code, form.Landline, form.Extn, form.Fax]);

return true;
sheet.getRange('A6').activate();
}

HTML 文件:Add_ClientContact.html

<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
(function () {
google.script.run.withSuccessHandler(
function (selectList) {
var select = document.getElementById("mySelectList");
for( var i=0; i<selectList.length; i++ ) {
var option = document.createElement("option");
option.text = selectList[i][0];
select.add(option);
}
}
).getSelectList();
}());

</script>
</head>

<form id="myForm" onsubmit="google.script.run
.withSuccessHandler(google.script.host.close)
.itemAdd_New(this)">

<p style="font-family:verdana;font-size:10pt;">
Title:
<select name="Title" required>
<option value="Mr.">Mr.</option>
<option value="Ms.">Ms.</option>
<option value="Sir/Madam">Sir/Madam</option>
</select>
<br><br>
Full Name: <input type="text" name="Full_Name" >
<br><br>
Friendly Company Name:
<select id="mySelectList" value="mySelectList" >
</select>
<br><br>
Designation: <input type="text" name="Designation">
<br><br>
Quotation Email: <input type="email" name="Email" >
<br><br>
Technical / Personal Email: <input type="email" name="Per_Email">
<br><br>
Mobile: <input type="text" name="Mobile">
<br><br>
STD Code: <input type="text" name="STD_Code">
<br><br>
Landline 1: <input type="text" name="Landline">
<br><br>
Extn: <input type="text" name="Extn">
<br><br>
Fax: <input type="text" name="Fax">
<br><br>

</p>
<input type="submit" value="SUBMIT and Re-open BLANK FORM" />

</font>
</form>
</html>

Screenshot of Google Sheet to capture Form Results

提前感谢大家的帮助!

最佳答案

也许这个简单的例子会有一些帮助:

html:

<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
window.onload=function(){
google.script.run
.withSuccessHandler(updateSelect)
.getSelectOptions();
}

function updateSelect(vA){
var select = document.getElementById("sel1");
select.options.length = 0;
for(var i=0;i<vA.length;i++)
{
select.options[i] = new Option(vA[i],vA[i]);
}
}

function savSelect(){
var selected=document.getElementById('sel1').value;
google.script.run
.withSuccessHandler(function(emails){
console.log(emails);
document.getElementById('emails').innerHTML='Send Emails to the following: '+emails;
})
.getEmailsForChoice(selected);
}
console.log('My Code');
</script>
</head>
<body>
<div id="emails"></div>
<select id="sel1" onChange="savSelect();"></select>
</body>
</html>

GS:

function onOpen(){
SpreadsheetApp.getUi().createMenu('My Tools')
.addItem('Test', 'showFormDialog')
.addItem('Show Choice Dialog','showMyDialog')
.addToUi();
}

function buildForm(){
var s='';
for(var i=0;i<5;i++){
s+=Utilities.formatString('<br /><input class="jim" type="text" value="" id="%s" />%s',"txt" + i,"text" + Number(i+1));
}
s+='<br /><input type="button" value="Submit" onClick="getValues();" /><input type="button" value="Close" onClick="google.script.host.close();" />';
return s;
}
function saveValues(A){
for(var i=0;i<A.length;i++){
Logger.log('\nid=%s\nvalue=%s',A[i].id,A[i].value);
}
}
function showFormDialog(){
var ui=HtmlService.createHtmlOutputFromFile('form')
SpreadsheetApp.getUi().showModelessDialog(ui,'My Form');
}

function getSelectOptions(){
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Selections')
var rg=sh.getDataRange();
var selections=[];
var vA=rg.getValues();
for (var i=0;i<vA.length;i++){
selections.push(vA[i][0]);
}
return selections;
}

function getEmailsForChoice(choice){
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Selections')
var rg=sh.getDataRange();
var vA=rg.getValues();
for (var i=0;i<vA.length;i++){
if(choice==vA[i][0]){
var emails=Utilities.formatString('%s;%s;%s',vA[i][1],vA[i][2],vA[i][3]);
break;
}
}
return emails;
}

function showMyDialog(){
var ui=HtmlService.createHtmlOutputFromFile('choices')
SpreadsheetApp.getUi().showModelessDialog(ui, 'Choices');
}

关于html - 使用 Google App Script 从单独的 Google 表格创建的 HTML 表单中的动态下拉列表中传递选择的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59492423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com