Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
Enter key as well as submit button on Google Script Code in Sheet

I would like to be able to use enter as well as the submit button to execute / accept data entry and commit to cell.

I cannot seem to get the code to work. Any advice how to modify?

      <script>
         var itemBox = document.getElementById("itemname");
        document.getElementById("btn").addEventListener("click",addRecord);
        function addRecord(){

          var name = itemBox.value;
          if(name.trim().length == 0){
             M.toast({html: "Please enter a valid barcode!"})
          } else{

          var data = {
            name:itemBox.value
          };
          google.script.run.appendData(data);
          itemBox.value = "";
        }
      }
      </script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Please read comments:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
<script>
  var itemBox = document.getElementById("itemname");
  document.getElementById("btn").addEventListener("click",addRecord);
  function addRecord(){
    var name = itemBox.value;//item box is undefined
    if(name.trim().length == 0){
      M.toast({html: "Please enter a valid barcode!"})//M is undefined and toast does not exist clientside
    } else{
      var data = {name:itemBox.value};
      google.script.run.appendData(data);
        itemBox.value = "";
    }
  }
</script>
  </body>
</html>

Spreadsheet.toast() is a server side method of Class Spreadsheet and is not intended to function clientside on the browser.

Spreadsheet.toast()

So far your description of your question is incomplete

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda