0

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]);
          }
        }
0

1 Answer 1

1

Issues:

  • DOM Elements, except form element are not legal parameters to server side functions

Solution:

  • 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]);
      }
    }

To Read:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.