Google App Script And Javascript: Accessing A Form Elements Inside Div Tags
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
Solution 1:
Issues:
- DOM Elements, except form element are not legal parameters to server side functions
Answer :
- Pass the form itself to server-side function, which will be converted to a form object.
Modified Code:
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]);
}
}
Post a Comment for "Google App Script And Javascript: Accessing A Form Elements Inside Div Tags"