Last active
March 11, 2019 23:19
-
-
Save franklinokech/4fbc6d53d69f64003619be75bed49c23 to your computer and use it in GitHub Desktop.
This is a simple google app script that captures what the user has typed in a html textbox and append the value and the current timestamp in a spreadsheet workbook as a row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This function renders the html file | |
*/ | |
function doGet(event){ | |
Logger.log(event); | |
return HtmlService.createHtmlOutputFromFile('page'); | |
} | |
function userClick(name){ | |
/* | |
Now we want to save whatever the username the user inputs in the text box into a spreadsheet. | |
First we have to store the spreadsheet into a variable by getting its id | |
*/ | |
var id="1beVqbhcXrDTUNDiqbgO9Q-VgXau6ixOOc03BMTNFCqM";//declare variable spreadsheet id | |
var ss=SpreadsheetApp.openById(id);//get the spreadsheet by ID and store in the ss variable | |
var wsName="Data";//Declare variable worksheet name | |
var ws=ss.getSheetByName(wsName);//get the work sheet by the name declared above | |
var currentTimeStampt=new Date();//create the currenttimestamp object from the Date Class | |
ws.appendRow([name,currentTimeStampt]);//rowContent is a one dimentional array. The Username get appended to the row in workbok | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
</head> | |
<body> | |
<h1>Hello</h1> | |
<input type="text" id="username"/> | |
<button id="btnRunIt">Run It</button> | |
<script> | |
document.getElementById('btnRunIt').addEventListener('click',doStuff); | |
function doStuff(){ | |
var uname=document.getElementById('username').value;//get the value the user input in the textbox | |
google.script.run.userClick(uname);//run server side function | |
document.getElementById('username').value='';//set the value of textbox to null after running | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tutorial link: