4

I created a Custom Dialog Window in Google Spreadsheet using Google App Script that looks like this:

enter image description here

How do I get the data from the window to my spreadsheet.

Here is my HTML code:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>

<form action="google.script.run.testing143()">
  Task Number:<br>
  <input type="text" name="taskNumber" value="">
  <br><br>
   Task Date:<br>
  <input type="text" name="taskDate" value="">
  <br><br>
   Customer Name:<br>
  <input type="text" name="customerName" value="">
  <br><br>
   Customer Site:<br>
  <input type="text" name="customerSite" value="">
  <br><br>
  <select>
  <option value="status">Status</option>
  <option value="complete">Complete</option>
  <option value="scheduled">Scheduled</option>
  <option value="reschedule">Reschedule</option>
  </select>
  <br><br>
   Status Date:<br>
  <input type="text" name="statusDAte" value="">
  <br><br>
   Location:<br>
  <input type="text" name="location" value="">
  <br><br>
   Description:<br>
  <input type="text" name="description" value="">
  <br><br>
  <input type="submit" value="Submit">
</form> 

  <script>
  function testing143(){
  Logger.log('With Success')  ///Doesn't work
  var lmnt = document.getElementByName('usrname'); //Wrong

  }
  </script>
  </body>
</html>

When I click 'submit' it takes me to an error 400 page. I can create a function that takes the data as a parameter like:

function getNewTask(number,date,status...) 

Can I use document.getElement ? If so how is that done?

Your help is sincerely appreciated!

1

1 Answer 1

5

I've taken your code and modified to work.

In Code.gs

function testing143(obj) {
  Logger.log(obj);
  return "hello";
}

In HTML file

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>

<form id="myForm">
  Task Number:<br>
  <input type="text" name="taskNumber" value="">
  <br><br>
   Task Date:<br>
  <input type="text" name="taskDate" value="">
  <br><br>
   Customer Name:<br>
  <input type="text" name="customerName" value="">
  <br><br>
   Customer Site:<br>
  <input type="text" name="customerSite" value="">
  <br><br>
  <select name="status">
  <option value="status">Status</option>
  <option value="complete">Complete</option>
  <option value="scheduled">Scheduled</option>
  <option value="reschedule">Reschedule</option>
  </select>
  <br><br>
   Status Date:<br>
  <input type="text" name="statusDate" value="">
  <br><br>
   Location:<br>
  <input type="text" name="location" value="">
  <br><br>
   Description:<br>
  <input type="text" name="description" value="">
  <br><br>
  <input type="button" value="Submit" onclick="testing143()">
</form> 

  <script>
  function success(msg) {
    alert(msg);
  }

  function testing143(){
    var form = document.getElementById("myForm").elements;
    var obj ={};
    for(var i = 0 ; i < form.length ; i++){
        var item = form.item(i);
        obj[item.name] = item.value;
    }
    google.script.run.withSuccessHandler(success).testing143(obj);
  }
  </script>
  </body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

Works beautifully. Thank you!

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.