David Menacho
David Menacho

Reputation: 173

Convert web document objects to a Spreadsheet function

Using and spreadsheet, I have an HTML web that fills some text boxes and create some google charts when a csv file is dropped (this is not a Form)

enter image description here

I need to make a function that let me parse the value of the text boxes in order to fill a spreadsheet, this is my code so far:

Tablas.html (I am trying to pass all the document object as a parameter)

    <input id="cmd" onclick="formSubmit()" type="button" value="Descargar SnapShot">
    <script type="text/javascript">
    function formSubmit() {
    google.script.run.getValuesFromForm(document);
    }

And the gs Script: (With the document as a parameter, i am trying to recover a text box named "modequ" to fill a new row in the Spreadsheet)

    function getValuesFromForm(document){
    var ssID   = "12GvIStMKqmRFNBM-C67NCDeb89-c55K7KQtcuEYmJWQ",
    sheet  = SpreadsheetApp.openById(ssID).getSheets()[0],
    modequ = document.getElementById("modequ").value;
    sheet.appendRow([modequ]);
    }

Is there any way to connect the all the document objects in the page made with the spreadsheet so i can append and process it? I though if maybe if i pass the all the document object this would be possible.

Regards

Upvotes: 1

Views: 57

Answers (1)

user3075569
user3075569

Reputation:

The document.getElementById() method returns a reference from the id attribute from your HTML, it needs to be inside your formSubmit() function:

  function formSubmit() {
    var modequ = document.getElementById('modequ').value;
    google.script.run.getValuesFromForm(modequ);
  }

This way you can get all the values individually and then pass them as parameter e.g. google.script.run.getValuesFromForm(modequ, tipmoto, smr)

However, if you want to pass all the form elements and then get them by name, you can do something like this:

HTML:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
   <form id="form" name="form">
     <input name="modequ" type="text">
     <input name="tipmoto" type="text">
     <input name="series" type="text">
     <input id="cmd" onclick="formSubmit()" type="button" value="Descargar SnapShot">
   </form>
  </body>
</html>
<script type="text/javascript">
function formSubmit(){
   google.script.run.getValuesFromForm(document.forms[0]);
}
</script>

GS:

function getValuesFromForm(res){
  var ssID   = '12GvIStMKqmRFNBM-C67NCDeb89-c55K7KQtcuEYmJWQ',
      sheet  = SpreadsheetApp.openById(ssID).getSheets()[0];

  sheet.appendRow([res.modequ, res.tipmoto, res.series]);
}

Upvotes: 2

Related Questions