在HTML下载列表中获取一个带有Selected Option的var到Google Script Spreadshee
Get a var with Selected Option in HTML downlist to Google Script Spreadsheet
我真的需要帮助我几乎完成了我的谷歌脚本,但我遇到了麻烦,我不知道如何从下载列表(html)中获得所选选项(所选月份),并将其存储在"var"中,我真的很感谢你的帮助。
我尝试使用getElementById,但没有成功。
谢谢。
文档代码.gs
/*** Retrieves all the rows in the active spreadsheet that contain data and logs the values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet*/
function Menu() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.createMenu("Christian's Menu")
.addItem('Side Bar Comites', 'showSidebar')
.addToUi();
}
function showSidebar() {
var html = HtmlService.createHtmlOutputFromFile('Page')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Sedesol - Captura de Entregas')
.setWidth(250);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showSidebar(html);
}
function autowritemonthday(form){
var storeMonth = getElementById('monthlist').value; /*Does not work i dont know why*/
Browser.msgBox(storeMonth); /*tried to view the value from var storeMonth*/
/*I put this as comment because does not work either
var e = document.getElementById('monthlist');
var val = e.options[e.selectedIndex].text;*/
/*I need Storage the selected value from the downlist here before the onSeach(form)*/
onSearch(form); /*call the function to search the input text and put the cursor in the right Cell*/
var hoja = SpreadsheetApp.getActiveSpreadsheet();
var sheet = hoja.getSheets()[0];
var rows = sheet.getDataRange();
var ss = hoja.getActiveCell()
var selectedrow = ss.getRow();
var selectedcol = ss.getColumn();
var monthpos = sheet.getRange(selectedrow, 7); /* get the cell position for example monthpost(5,7)*/
var daypos = sheet.getRange(selectedrow, 8);
var tempm = form.mesinini; /*get the value of the inputbox by NAME*/
var tempd = form.dias;
var remspacestxtmonth = tempm.trim(); /*remove blank spaces*/
var uppertxtmonth = remspacestxtmonth.toUpperCase();/*conv. to uppercase*/
var remspacestxtday = tempd.trim(); /*remove blank spaces*/
monthpos.setValue(uppertxtmonth); /*write the var value in the selected cell preview positioned by the function onSearch*/
daypos.setValue(remspacestxtday);
}
function doGet() {
return HtmlService.createHtmlOutputFromFile("Page");
}
function onSearch(form){
var tempc = form.comites;
var comite = tempc.trim();
/*Browser.msgBox(comite);*/
var searchString = comite;
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("REYNOSA");
var column =4; //column Index - where i am going to search the value of the var comite
var columnValues = sheet.getRange(2, column, sheet.getLastRow()).getValues(); //1st cell Titles
var searchResult = columnValues.findIndex(searchString); //Cell Index - 2
if(searchResult != -1)
{
//searchResult + 2 is row index.
SpreadsheetApp.getActiveSpreadsheet().setActiveRange(sheet.getRange(searchResult + 2, 1))
}
}
Array.prototype.findIndex = function(search){
if(search == "") return false;
for (var i=0; i<this.length; i++)
if (this[i] == search) return i;
return -1;
}
Array.prototype.findIndex = function(search){
if(search == "") return false;
for (var i=0; i<this.length; i++)
if (this[i] == search) return i;
return -1;
}
page.html
<head>
<title>Page</title>
</head>
<body>
<div>
<form>
INGRESA LA FECHA DE ENTREGA QUE DESEAS UTILIZAR PARA LOS COMITES... /EN/...WRITE THE DATE YOU ARE GOING TO USE TO CAPTURE THE RECEIPTS
<br><br/>
<select id="monthlist" name="monthlist">
<option value="enero">JANUARY</option>
<option value="febrero">FEBRUARY</option>
<option value="marzo">MARCH</option>
<option value="abril">APRIL</option>
<option value="mayo">MAY</option>
<option value="Junio">JUNE</option>
<option value="julio">JULY</option>
<option value="agosto">AUGUST</option>
<option value="septiembre">SEPTEMBER</option>
<option value="octubre">OCTOBER</option>
<option value="noviembre">NOVEMBER</option>
<option value="diciembre">DECEMBER</option>
</select>
<br><br/>
Ingresa el MES [EJEMPLO: MARZO]: /EN/WRITE THE MONTH <input id="resp" type="text" value="" name="mesinini" />
<br><br/>
Ingresa el DIA /EN/WRITE THE DAY OF THE MONTH [EJEMPLO: 14]: <input id="resp" type="text" value="" name="dias" />
<br><br/>
CAPTURA EL COMITE. /EN/ CAPTURE THE RECEIPT NUMBER
<br><br/>
Ingresa el Comite: /EN/ WRITE THE RECEIPT NUMBER <input id="resp" type="text" value="" name="comites" />
<br><br/>
<input type="button" onclick="formautomd()" value="Capturar Entrega del Comite"/> /*THIS BUTTON*/
<br><br/>
<input type="button" onclick="formonSearch()" value="Buscar Comite"/>
<br><br/>
<input type="button" onclick="formexit()" value="Salir del Menu"/>
</form>
</div>
</body>
<script type="text/javascript">
function formonSearch() {
/////even tried to put the getElementbyId here and same result.
google.script.run.onSearch(document.forms[0]);
}
function formautomd() {
google.script.run.autowritemonthday(document.forms[0]);
} /* IT NEED BE STORAGED WHEN I PRESS THIS BUTTON*/
function formexit(){
google.script.host.close();
}
</script>
getElementById()
不能在.gs
服务器代码中使用。.gs
脚本在谷歌的服务器上运行。getElementById()
仅适用于浏览器。您的功能:
function autowritemonthday(form){
var storeMonth = getElementById('monthlist').value;
/*Does not work i dont know why*/
在.gs
代码中。getElementById()
仅适用于HTML中的<script>
标记。
所需的数据必须来自"form"对象。
这就是你需要使用的:
var storeMonth = form["monthlist"];
要查看表单对象中的内容,请遍历表单对象,如下所示:
function autowritemonthday(form){
Logger.log('form: ' + form);
for (var key in form) {
Logger.log('the key is: ' + key);
Logger.log('the value is: ' + form[key]);
};
return;
};
提交表单,然后在代码编辑器中,选择VIEW菜单,然后选择LOGS。
我最初的答案:
你试过这样的东西吗:
function formautomyd() {
var storeMonth = getElementById('monthlist').value;
google.script.run.autofechaydia(document.forms[0]);
}
您声明您使用了:
getElementByID
但没有显示代码。末尾的字母"D"不能大写。必须是小写。getElementById()
相关文章:
- 更改基于它的Select OPTION's INDEX(Jquery)
- 使用Dalekjs测试工具,如何在Dropdown中选择Option(select元素)当没有“;值“;Option标记
- 如何设置Dojo表单中的selected选项
- Jquery Selected plugin - 由 Ajax 动态填充列表
- Angularjs ng-options selected value of dropdownlist
- 选择/选项 ng-model 未绑定 ng-selected
- jQuery val() 返回一个在 select/option 元素上带有 IE8 的数组
- 在应用 jQuery.Selected 时,使用 jQuery.Validate 来验证选择字段时,暴露错误
- 如何使我的.selected类在hrefs列表中重新加载后保持在正确的a(href)上
- Jquery-使用HTML:selected来获取具有相同名称的数组
- 根据select option元素将表单重定向到不同的URL,但重定向后未选中
- `object:selected`事件触发两次
- jQueryMobile-如果输入是selected,则固定的标头会更改大小
- 在HTML下载列表中获取一个带有Selected Option的var到Google Script Spreadshee
- append to select option
- option not selected angularjs select
- $('select option:selected').text()和Attr.指定的已弃用警告
- 在JQuery中为select-option-selected编写ID选择器的正确语法是什么?
- 需要从表单中获取Selected Option值,并通过jquery/javascript返回
- html-select <option selected=""> doesn't