How do I get data from a sheet to my drop-down box

211 Views Asked by At

I am trying to make a drop-down box (select), and get the options from a sheet, but I can't get it to work. Actually the problem is, that I have to wait for the script.run to finish, before I add to the select. I therefore moved the add, to the successhandler-function, but somehow it doesn't do anything. If I run it, as this I only get option 1 and 2.

My document look like this:

The server-side code looks like this, stripped down to nothing, just to make sure the miss isn't coming from here.

 <!DOCTYPE html>
  <html>
    <head>
      <!--Import Google Icon Font-->
      <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

     <!-- Compiled and minified CSS -->
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

      <!--Let browser know website is optimized for mobile-->
      <meta dato="viewport" content="width=device-width, initial-scale=1.0"/>


    </head>
    <body>

    <div class="container">

       <div class="row">

         <form action="/action_page.php" id="inputform">

            <div class="input-field">          
              <input id="tekst" type="text" class="validate">
              <label class="active" for="tekst">Tekst</label>
            </div>

            <div class="input-field">

              <select name="Choose" id="Choose"> 
              <option value="" selected disabled hidden> Choose</option> 

              </select> 
            </div>         

          </form><!--- end form


            <!-- Compiled and minified JavaScript -->
       <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
       <script>

        document.addEventListener('DOMContentLoaded', function() {
            var elems = document.querySelectorAll('select');
            var instances = M.FormSelect.init(elems);
            var instance = M.FormSelect.getInstance(elem);            
        });


         var konto = "Choose";
         var x = document.getElementById("Choose");        
         var option = document.createElement("option");
         option.text = "Option 1";
         x.add(option);        

         google.script.run.withSuccessHandler(fillOption).getOption();

         var option = document.createElement("option");
         option.text = "Option 2";
         x.add(option);


         function fillOption(){  

            var konto = "Choose";
            var x = document.getElementById("Choose"); 
            var option = document.createElement("option");
            option.text = "Option 3";
            x.add(option);

         }  

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

The serverside code looks like this, stripped down to nothing, just to make sure the miss isnt comming from here.

 function onOpen() {

 var template = HtmlService.createTemplateFromFile("userform");

var html = template.evaluate();

 html.setTitle("Just testing select").setHeight(500).setWidth(700);

 SpreadsheetApp.getUi().showModelessDialog(html, "testing");

}

function getOption() {    

}
0

There are 0 best solutions below