How to get the value of a html select form in Google App Script?












1















I have a HTML form in Google App Script



HTML:



<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body onload="myFunction()">

<form id="myForm" >
<select id="mySelection" name="establishment" style="width:300px">
</select>
<br>
<input type="button" class="button" value="Submit" name="button" onclick="getEstValues()">
</form>
<br>

<script>
//Redundant success function:
function success(msg) {
};
//Triggered onload gets parameter as callback function from opOpen.gs updateEstselect().
function myFunction(array) {
//Loops through the array of est.
for(var i = 0 ;i < array.length; i++){
//Create an element.
var element = document.createElement("option");
//Insert Test into the element tags created above.
var textnode = document.createTextNode(array[i]);
//Append the text node to the element tags.
element.appendChild(textnode);
//appends the <option> to <select> as a child.
document.getElementById("mySelection").appendChild(element);
};
};


//Triggers the above function onload then uses the value returned from updateEstSelect as a callback param for myFunction()
google.script.run
.withSuccessHandler(myFunction)
.updateEstSelect();


function getEstValues(){
//Gets the form
var form = document.getElementById("myForm").elements;
//Creates an object with the form names and values.
var obj ={};
for(var i = 0 ; i < form.length ; i++){
var item = form.item(i);
obj[item.name] = item.value;
}
//Triggers GAS side getEstValues(obj) function.
google.script.run
.withSuccessHandler(function(e) {
success(e);
google.script.host.close();
})
.getEstValues(obj);
//Closes HTML box.
google.script.host.close();
};
</script>
</body>
</html>


JS:



function getEstValues(obj){
Logger.log(obj);
return obj;
}


The HTML box loads perfectly when requested but when I check the log, there's nothing to view. When I click on the submit button onclick="getEstValues()" runs this getEstValues() which then gets the form with myForm , then iterates through the array, creates an object using name as the key and value as the value which then runs .getEstValues(obj); with success handler then closes the HTML box with google.script.host.close();



The problem:



It doesn't log but when I click submit the HTML box closes.
Log:



No logs found. Use Logger API to add logs to your project.


enter image description here










share|improve this question



























    1















    I have a HTML form in Google App Script



    HTML:



    <!DOCTYPE html>
    <html>
    <head>
    <base target="_top">
    </head>
    <body onload="myFunction()">

    <form id="myForm" >
    <select id="mySelection" name="establishment" style="width:300px">
    </select>
    <br>
    <input type="button" class="button" value="Submit" name="button" onclick="getEstValues()">
    </form>
    <br>

    <script>
    //Redundant success function:
    function success(msg) {
    };
    //Triggered onload gets parameter as callback function from opOpen.gs updateEstselect().
    function myFunction(array) {
    //Loops through the array of est.
    for(var i = 0 ;i < array.length; i++){
    //Create an element.
    var element = document.createElement("option");
    //Insert Test into the element tags created above.
    var textnode = document.createTextNode(array[i]);
    //Append the text node to the element tags.
    element.appendChild(textnode);
    //appends the <option> to <select> as a child.
    document.getElementById("mySelection").appendChild(element);
    };
    };


    //Triggers the above function onload then uses the value returned from updateEstSelect as a callback param for myFunction()
    google.script.run
    .withSuccessHandler(myFunction)
    .updateEstSelect();


    function getEstValues(){
    //Gets the form
    var form = document.getElementById("myForm").elements;
    //Creates an object with the form names and values.
    var obj ={};
    for(var i = 0 ; i < form.length ; i++){
    var item = form.item(i);
    obj[item.name] = item.value;
    }
    //Triggers GAS side getEstValues(obj) function.
    google.script.run
    .withSuccessHandler(function(e) {
    success(e);
    google.script.host.close();
    })
    .getEstValues(obj);
    //Closes HTML box.
    google.script.host.close();
    };
    </script>
    </body>
    </html>


    JS:



    function getEstValues(obj){
    Logger.log(obj);
    return obj;
    }


    The HTML box loads perfectly when requested but when I check the log, there's nothing to view. When I click on the submit button onclick="getEstValues()" runs this getEstValues() which then gets the form with myForm , then iterates through the array, creates an object using name as the key and value as the value which then runs .getEstValues(obj); with success handler then closes the HTML box with google.script.host.close();



    The problem:



    It doesn't log but when I click submit the HTML box closes.
    Log:



    No logs found. Use Logger API to add logs to your project.


    enter image description here










    share|improve this question

























      1












      1








      1








      I have a HTML form in Google App Script



      HTML:



      <!DOCTYPE html>
      <html>
      <head>
      <base target="_top">
      </head>
      <body onload="myFunction()">

      <form id="myForm" >
      <select id="mySelection" name="establishment" style="width:300px">
      </select>
      <br>
      <input type="button" class="button" value="Submit" name="button" onclick="getEstValues()">
      </form>
      <br>

      <script>
      //Redundant success function:
      function success(msg) {
      };
      //Triggered onload gets parameter as callback function from opOpen.gs updateEstselect().
      function myFunction(array) {
      //Loops through the array of est.
      for(var i = 0 ;i < array.length; i++){
      //Create an element.
      var element = document.createElement("option");
      //Insert Test into the element tags created above.
      var textnode = document.createTextNode(array[i]);
      //Append the text node to the element tags.
      element.appendChild(textnode);
      //appends the <option> to <select> as a child.
      document.getElementById("mySelection").appendChild(element);
      };
      };


      //Triggers the above function onload then uses the value returned from updateEstSelect as a callback param for myFunction()
      google.script.run
      .withSuccessHandler(myFunction)
      .updateEstSelect();


      function getEstValues(){
      //Gets the form
      var form = document.getElementById("myForm").elements;
      //Creates an object with the form names and values.
      var obj ={};
      for(var i = 0 ; i < form.length ; i++){
      var item = form.item(i);
      obj[item.name] = item.value;
      }
      //Triggers GAS side getEstValues(obj) function.
      google.script.run
      .withSuccessHandler(function(e) {
      success(e);
      google.script.host.close();
      })
      .getEstValues(obj);
      //Closes HTML box.
      google.script.host.close();
      };
      </script>
      </body>
      </html>


      JS:



      function getEstValues(obj){
      Logger.log(obj);
      return obj;
      }


      The HTML box loads perfectly when requested but when I check the log, there's nothing to view. When I click on the submit button onclick="getEstValues()" runs this getEstValues() which then gets the form with myForm , then iterates through the array, creates an object using name as the key and value as the value which then runs .getEstValues(obj); with success handler then closes the HTML box with google.script.host.close();



      The problem:



      It doesn't log but when I click submit the HTML box closes.
      Log:



      No logs found. Use Logger API to add logs to your project.


      enter image description here










      share|improve this question














      I have a HTML form in Google App Script



      HTML:



      <!DOCTYPE html>
      <html>
      <head>
      <base target="_top">
      </head>
      <body onload="myFunction()">

      <form id="myForm" >
      <select id="mySelection" name="establishment" style="width:300px">
      </select>
      <br>
      <input type="button" class="button" value="Submit" name="button" onclick="getEstValues()">
      </form>
      <br>

      <script>
      //Redundant success function:
      function success(msg) {
      };
      //Triggered onload gets parameter as callback function from opOpen.gs updateEstselect().
      function myFunction(array) {
      //Loops through the array of est.
      for(var i = 0 ;i < array.length; i++){
      //Create an element.
      var element = document.createElement("option");
      //Insert Test into the element tags created above.
      var textnode = document.createTextNode(array[i]);
      //Append the text node to the element tags.
      element.appendChild(textnode);
      //appends the <option> to <select> as a child.
      document.getElementById("mySelection").appendChild(element);
      };
      };


      //Triggers the above function onload then uses the value returned from updateEstSelect as a callback param for myFunction()
      google.script.run
      .withSuccessHandler(myFunction)
      .updateEstSelect();


      function getEstValues(){
      //Gets the form
      var form = document.getElementById("myForm").elements;
      //Creates an object with the form names and values.
      var obj ={};
      for(var i = 0 ; i < form.length ; i++){
      var item = form.item(i);
      obj[item.name] = item.value;
      }
      //Triggers GAS side getEstValues(obj) function.
      google.script.run
      .withSuccessHandler(function(e) {
      success(e);
      google.script.host.close();
      })
      .getEstValues(obj);
      //Closes HTML box.
      google.script.host.close();
      };
      </script>
      </body>
      </html>


      JS:



      function getEstValues(obj){
      Logger.log(obj);
      return obj;
      }


      The HTML box loads perfectly when requested but when I check the log, there's nothing to view. When I click on the submit button onclick="getEstValues()" runs this getEstValues() which then gets the form with myForm , then iterates through the array, creates an object using name as the key and value as the value which then runs .getEstValues(obj); with success handler then closes the HTML box with google.script.host.close();



      The problem:



      It doesn't log but when I click submit the HTML box closes.
      Log:



      No logs found. Use Logger API to add logs to your project.


      enter image description here







      html google-apps-script






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 28 '18 at 15:26









      Brandon Pillay Brandon Pillay

      8218




      8218
























          1 Answer
          1






          active

          oldest

          votes


















          1















          • When you clicked the submit button, you want to see the log at Logger.log(obj) of getEstValues(obj).


          If my understanding is correct, how about this modification?



          Modification points:




          • When there is google.script.host.close() of the bottom in the function getEstValues(), google.script.host.close()'' is run before the work ofgoogle.script.runis finished completely. Becausegoogle.script.run`` works by the asynchronous processing.

          • I thought that google.script.host.close() of the bottom might be not required because google.script.host.close() in withSuccessHandler is run.


          Modified script



          Please modify getEstValues() in HTML.



          function getEstValues(){
          //Gets the form
          var form = document.getElementById("myForm").elements;
          //Creates an object with the form names and values.
          var obj = {};
          for (var i = 0 ; i < form.length ; i++) {
          var item = form.item(i);
          obj[item.name] = item.value;
          }
          //Triggers GAS side getEstValues(obj) function.
          google.script.run
          .withSuccessHandler(function(e) {
          success(e);
          google.script.host.close();
          })
          .getEstValues(obj);
          //Closes HTML box.
          // google.script.host.close(); // <----- Modified
          }


          If I misunderstand your issue, please tell me. I would like to modify it.






          share|improve this answer
























          • Thanks for the feedback!

            – Brandon Pillay
            Nov 29 '18 at 18:34











          • @Brandon Pillay Welcome. I'm glad your issue was resolved.

            – Tanaike
            Nov 29 '18 at 22:24











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53522860%2fhow-to-get-the-value-of-a-html-select-form-in-google-app-script%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1















          • When you clicked the submit button, you want to see the log at Logger.log(obj) of getEstValues(obj).


          If my understanding is correct, how about this modification?



          Modification points:




          • When there is google.script.host.close() of the bottom in the function getEstValues(), google.script.host.close()'' is run before the work ofgoogle.script.runis finished completely. Becausegoogle.script.run`` works by the asynchronous processing.

          • I thought that google.script.host.close() of the bottom might be not required because google.script.host.close() in withSuccessHandler is run.


          Modified script



          Please modify getEstValues() in HTML.



          function getEstValues(){
          //Gets the form
          var form = document.getElementById("myForm").elements;
          //Creates an object with the form names and values.
          var obj = {};
          for (var i = 0 ; i < form.length ; i++) {
          var item = form.item(i);
          obj[item.name] = item.value;
          }
          //Triggers GAS side getEstValues(obj) function.
          google.script.run
          .withSuccessHandler(function(e) {
          success(e);
          google.script.host.close();
          })
          .getEstValues(obj);
          //Closes HTML box.
          // google.script.host.close(); // <----- Modified
          }


          If I misunderstand your issue, please tell me. I would like to modify it.






          share|improve this answer
























          • Thanks for the feedback!

            – Brandon Pillay
            Nov 29 '18 at 18:34











          • @Brandon Pillay Welcome. I'm glad your issue was resolved.

            – Tanaike
            Nov 29 '18 at 22:24
















          1















          • When you clicked the submit button, you want to see the log at Logger.log(obj) of getEstValues(obj).


          If my understanding is correct, how about this modification?



          Modification points:




          • When there is google.script.host.close() of the bottom in the function getEstValues(), google.script.host.close()'' is run before the work ofgoogle.script.runis finished completely. Becausegoogle.script.run`` works by the asynchronous processing.

          • I thought that google.script.host.close() of the bottom might be not required because google.script.host.close() in withSuccessHandler is run.


          Modified script



          Please modify getEstValues() in HTML.



          function getEstValues(){
          //Gets the form
          var form = document.getElementById("myForm").elements;
          //Creates an object with the form names and values.
          var obj = {};
          for (var i = 0 ; i < form.length ; i++) {
          var item = form.item(i);
          obj[item.name] = item.value;
          }
          //Triggers GAS side getEstValues(obj) function.
          google.script.run
          .withSuccessHandler(function(e) {
          success(e);
          google.script.host.close();
          })
          .getEstValues(obj);
          //Closes HTML box.
          // google.script.host.close(); // <----- Modified
          }


          If I misunderstand your issue, please tell me. I would like to modify it.






          share|improve this answer
























          • Thanks for the feedback!

            – Brandon Pillay
            Nov 29 '18 at 18:34











          • @Brandon Pillay Welcome. I'm glad your issue was resolved.

            – Tanaike
            Nov 29 '18 at 22:24














          1












          1








          1








          • When you clicked the submit button, you want to see the log at Logger.log(obj) of getEstValues(obj).


          If my understanding is correct, how about this modification?



          Modification points:




          • When there is google.script.host.close() of the bottom in the function getEstValues(), google.script.host.close()'' is run before the work ofgoogle.script.runis finished completely. Becausegoogle.script.run`` works by the asynchronous processing.

          • I thought that google.script.host.close() of the bottom might be not required because google.script.host.close() in withSuccessHandler is run.


          Modified script



          Please modify getEstValues() in HTML.



          function getEstValues(){
          //Gets the form
          var form = document.getElementById("myForm").elements;
          //Creates an object with the form names and values.
          var obj = {};
          for (var i = 0 ; i < form.length ; i++) {
          var item = form.item(i);
          obj[item.name] = item.value;
          }
          //Triggers GAS side getEstValues(obj) function.
          google.script.run
          .withSuccessHandler(function(e) {
          success(e);
          google.script.host.close();
          })
          .getEstValues(obj);
          //Closes HTML box.
          // google.script.host.close(); // <----- Modified
          }


          If I misunderstand your issue, please tell me. I would like to modify it.






          share|improve this answer














          • When you clicked the submit button, you want to see the log at Logger.log(obj) of getEstValues(obj).


          If my understanding is correct, how about this modification?



          Modification points:




          • When there is google.script.host.close() of the bottom in the function getEstValues(), google.script.host.close()'' is run before the work ofgoogle.script.runis finished completely. Becausegoogle.script.run`` works by the asynchronous processing.

          • I thought that google.script.host.close() of the bottom might be not required because google.script.host.close() in withSuccessHandler is run.


          Modified script



          Please modify getEstValues() in HTML.



          function getEstValues(){
          //Gets the form
          var form = document.getElementById("myForm").elements;
          //Creates an object with the form names and values.
          var obj = {};
          for (var i = 0 ; i < form.length ; i++) {
          var item = form.item(i);
          obj[item.name] = item.value;
          }
          //Triggers GAS side getEstValues(obj) function.
          google.script.run
          .withSuccessHandler(function(e) {
          success(e);
          google.script.host.close();
          })
          .getEstValues(obj);
          //Closes HTML box.
          // google.script.host.close(); // <----- Modified
          }


          If I misunderstand your issue, please tell me. I would like to modify it.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 28 '18 at 22:52









          TanaikeTanaike

          23.6k21325




          23.6k21325













          • Thanks for the feedback!

            – Brandon Pillay
            Nov 29 '18 at 18:34











          • @Brandon Pillay Welcome. I'm glad your issue was resolved.

            – Tanaike
            Nov 29 '18 at 22:24



















          • Thanks for the feedback!

            – Brandon Pillay
            Nov 29 '18 at 18:34











          • @Brandon Pillay Welcome. I'm glad your issue was resolved.

            – Tanaike
            Nov 29 '18 at 22:24

















          Thanks for the feedback!

          – Brandon Pillay
          Nov 29 '18 at 18:34





          Thanks for the feedback!

          – Brandon Pillay
          Nov 29 '18 at 18:34













          @Brandon Pillay Welcome. I'm glad your issue was resolved.

          – Tanaike
          Nov 29 '18 at 22:24





          @Brandon Pillay Welcome. I'm glad your issue was resolved.

          – Tanaike
          Nov 29 '18 at 22:24




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53522860%2fhow-to-get-the-value-of-a-html-select-form-in-google-app-script%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)