Tuesday, October 29, 2013

Get value of html text box in Apps Script function


-----------------------------------------Code.gs----------------------------------------------------------
// Script-as-app template.
function doGet() {
  return HtmlService.createHtmlOutputFromFile('index');
}


function doSomething(form) {
var SpreadSheetKey = "0AkifnI9MF2E2dExYUFQxcmZGSU5ZbUtnMzFkTllVM2c";
   
   var sheet = SpreadsheetApp.openById(SpreadSheetKey).getActiveSheet();
  textBoxValue = form.textBoxName;
  var lastRow = sheet.getLastRow();

  var targetRange = sheet.getRange(lastRow+1, 1, 1, 1).setValues([[textBoxValue]]);
}

---------------------------------------------index.html----------------------------------------------------

<script>
 function formSubmit() {
            google.script.run.doSomething(document.forms[0]);
        }
</script>

<form>

<input type="button" value="Not Clicked"
    onclick="formSubmit()" />  
<input type="text" name="textBoxName" />
</form>

No comments:

Post a Comment