Reputation: 55
I'd like to access an input element inside a form and a div. I'm new to Google app script and I believe I need to pass an argument that contains the DOM address from a JS function to an app script function.
Here's the code:
Javascript:
<script>
function update()
{
google.script.run.selectCell(document.getElementById(location));
alert("Success");//test message
}
</script>
HTML code:
<div class="container">
<form>
<div class="row">
<div class="col-25">
<label for="location">Location</label>
</div>
<div class="col-75">
<input type="text" id="location" name="location_txt" placeholder="The location..">
</div>
</div>
<div class="row">
<input type="button" onclick="update()" value="Update">
</div>
Google App Script:
function selectCell(domAddress)
{
var val0 = domAddress.value;
if (cell)
{
sheet.appendRow([val0]);
}
}
Upvotes: 0
Views: 1219
Reputation: 50799
ClientSide:
<div class="container">
<form id ="myForm">
<div class="row">
<div class="col-25">
<label for="location">Location</label>
</div>
<div class="col-75">
<input type="text" id="location" name="location_txt" placeholder="The location..">
</div>
</div>
<div class="row">
<input type="button" onclick="update()" value="Update">
</div>
</form>
<script>
function update()
{
google.script.run.selectCell(document.getElementById('myForm'));
alert("Success");//test message
}
</script>
Server-side:
function selectCell(formObject)
{
var val0 = formObject['location_txt']
if (val0)
{
sheet.appendRow([val0]);
}
}
Upvotes: 1