Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda