Find information from my HMTL via Javascript in Google Script. error(Document is not defined)

Asked

Viewed 8 times

-1

Good afternoon guys. It’s my first post, but I always come here to seek knowledge. today I’m having a problem that the copilator of google script does not see a command to trigger a Function.

When I’m inside the HTML and call onclick, it executes. But if I search for any HTML references with the ID, by Document.getElementById("xxx"). value; for example it shows me the error of "Document is not defined"

I would like to solve this problem with "Document" and be able to pull my HTML references to Js.

Here’s the code I’m running.

<!DOCTYPE html>
  <html>
    <head>

      <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
      
      <script>
     
     var CampoNome = document.getElementById("Vendedor");
     var CampoTel = document.getElementById("Tel");
     
     document.getElementById("botao").addEventListener("Salvar", btt);
     
     function btt() {
     
      Logger.log("execute");
      var Nome = CampoNome.value;
      var Tel = CampoTel.value;
      M.toast({html : 'Executou'});
     
      if (Nome.trim().length == 0 || Tel.trim().length == 0){
     
        M.toast({html : 'Preencher todos os campos!'});
     
      }else{
     
         var Dados = {
     
         Nome: CampoNome.value,
         Tel: CampoTel.value
     
     };
       google.script.run.RegistrarVendedor(Dados);
       
        CampoNome.value = "";
        CampoTel.value = "";
        
        M.toast({html : 'Cadastro Importado com Sucesso!'});
     };
     }
     
     
     </script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
      
    </head>
    
    <body> 
    
    <div class = "container">      

      <div class="row">
        <div class="input-field col s12">
          <i class="material-icons prefix">account_circle</i>
          <input id="Vendedor" type="text" class="validate">
          <label for="Vendedor">Nome</label>
        </div>
        <div class="input-field col s12">
          <i class="material-icons prefix">phone</i>
          <input id="Tel" type="text" class="validate">
          <label for="Tel">Telefone</label>
        </div>
        <div class="input-field col s12">
        
          <button class="btn waves-effect waves-light" id= "botao"> Salvar
            <i class="material-icons right">send</i>
          </button>
          
          <input type="button" value="Salvar"
      onclick="google.script.run
      .RegistrarVendedor(Dados)"
      />
        </div>
      </div>
    </div>      


    <!-- Compiled and minified JavaScript -->


    </body>
  </html>

function doGet() {

  return HtmlService.createHtmlOutputFromFile("page");
  
}

function FormVendedor() {

var Form = HtmlService.createTemplateFromFile("page");

var MostrarForm = Form.evaluate();

MostrarForm.setTitle("Cadastro de Vendedores").setHeight(1000).setWidth(1000);

//SpreadsheetApp.getUi().showModalDialog(MostrarForm, "Cadastro de Vendedores");

SpreadsheetApp.getUi().showModalDialog(MostrarForm, "Cadastro de Vendedores");

//SpreadsheetApp.getUi().showSidebar(MostrarForm);

//SpreadsheetApp.getUi().showModelessDialog(MostrarForm, "Cadastro de Vendedores");

}


function RegistrarVendedor(Dados) {

Logger.log("Execute");

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("teste");

ss.getActiveCell();
ss.getRange(1,2).setValue("-");
ss.getRange("b1").activate();
ss.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
ss.getActiveCell().offset(1,0).activate();

var linha = ss.getCurrentCell().getRow();

ss.getRange(linha,2).setValue([Dados.Nome]);
ss.getRange(linha,3).setValue([Dados.Tel]);



}

I’m not too concerned about the other commands, in case they see any mistakes. I just wanted to run a Function() any, that accepts I click the button and fetch the values that form inserted.

Sincerely yours.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.