I need to pass a data value from the HTML to the Google Script on a GAS project. The parts with comments of the code is the value I need to pass.
gs file
function doGet(e) {
if (e.parameter.prefix){
var result = data; // <-- GET VALUE "data" FROM THE HTML "forms.html"
var content = e.parameters.prefix + '(' +JSON.stringify(result) + ')';
return ContentService.createTextOutput(content)
.setMimeType(ContentService.MimeType.JAVASCRIPT);
}
var html = HtmlService.createHtmlOutputFromFile('Index');
return html.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
Index.html in GAS project
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1 id='title' style="color: #e31414">SCRIPT</h1>
<h1 id='done' style="display: none"> DATA PASSED</h1>
<button id="btn" onclick="passData()">Run "passData()"</button>
</body>
</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
function passData() {
$('#done').show();
var data = 'value'; //<-- PASS THIS DATA TO GOOGLE SCRIPT (The .gs file)
}
</script>