【发布时间】:2020-08-11 09:00:32
【问题描述】:
我很难让它工作,除了依赖下拉菜单外一切正常,我做错了什么吗?
我正在尝试将此添加到使用工作表的谷歌工作表脚本中,除了依赖下拉列表之外,它似乎都可以工作。
这是我得到的错误:
Uncaught ReferenceError: nameCheck is not defined
如果我在 HTML 测试仪上测试此代码,它似乎可以正常工作,但是,它似乎无法在 google 表格中工作。
<html lang="en">
<body>
<h4>Add a Customer</h4>
Select a Date: <input type="date" id="date" name="start" class="mb-3">
<div>
Sales Rep:
<select id="rep">
<option>select option</option>
<option>Neil</option>
<option>Dave</option>
<option>Bob</option>
<option>Trick</option>
</select>
</div>
<div class="add-customer-form">
<div class="form-group">
<label for="first-name">Company name : </label>
<input type="text" class="form-control" id="first-name">
</div>
<div>
Product type:
<select id="input" onchange="nameCheck()">
<option>select option</option>
<option>CASH</option>
<option>Training</option>
<option>Optional Modules</option>
<option>Annual Additional Modules</option>
<option>Hosting Existing user moving Licence</option>
<option>Rentals</option>
<option>Existing Customer - Rentals</option>
<option>Existing Customer - CASH</option>
<option>other</option>
google.script.run.nameCheck();
console.log(input);
</select>
<div>
Product:
<select id="output" onchange="nameCheck()">
</select>
</div>
</div>
</div>
<div class="form-group">
<label for="first-name">Quantity : </label>
<input type="number" class="form-control" id="last-name">
</div>
<div class="form-group mt-3">
<label for="phone-number">Previous CAD : </label>
<input type="text" class="form-control" id="phone-number">
<div class="form-group">
<label for="sales-price">Sales Price : </label>
<input type="number" class="form-control" id="salesP">
</div>
<div class="form-group">
<label for="deposit">Deposit : </label>
<input type="number" class="form-control" id="deposit">
</div>
<div class="form-group">
<label for="install">No. Intallments : </label>
<input type="number" class="form-control" id="install">
</div>
<div class="form-group">
<label for="invoice">Invoice Nr : </label>
<input type="text" class="form-control" id="invoice">
</div>
<div class="form-group">
<label for="Notes">Notes : </label>
<input type="text" class="form-control" id="notes">
</div>
<button class="btn btn-primary" id="add-customer-button">Add Customer</button>
</div>
<div class="alert alert-success invisible mt-3" id="save-success-message" role="alert">
Successfully Added!!
</div>
<script>
function nameCheck(){
var a=document.getElementById("input").value;
console.log(a);
if(a==="CASH")
{
var arr=["Cash 1","cash2"];
}
else if(a==="Existing Customer - CASH")
{
var arr=["existing 1", "existing 2"];
}
else if(a==="Training")
{
var arr=["Level 1 Training (in-house)","Level 2 Training (in-house)","Level 3 Training (in-house)","Onsite Training (up to 4 people)","Training Online per hour","Principles of Design (Renee Mascari)","Graham Hayden Sales/Care","KBBConnect training (per hours)","Training Solus (in-house) - 8 people"];
}
var string="";
for(i=0;i<arr.length;i++)
{
string=string+"<option value="+arr[i]+">"+arr[i]+"</option>";
}
document.getElementById("output").innerHTML=string;
}
</script>
</body>
</html>
截屏对话框:
【问题讨论】:
-
定义“不起作用”的含义(请永远在未确定具体细节的情况下提出问题)。另外,“在 Google 表格中”是什么意思?
-
我在谷歌表格中使用脚本编辑器,在 HTML 页面上可以使用什么
-
Henri,对不起,但这对我来说没有意义。你到底在做什么?自定义对话框/菜单?侧边栏?碰巧也是绑定脚本项目的 Web 应用程序?此外,脚本编辑器只是 Google 提供的 Web IDE,是 Apps 脚本平台的一部分。
-
我正在创建一个销售板,但数据将通过应用程序添加。所以目前我只是想让依赖下拉菜单工作,所以如果选择了产品类型,它会给我一个取决于产品类型的产品
-
我通过对话框道歉,我将在帖子中添加屏幕截图
标签: javascript google-apps-script google-sheets