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

270
Visualizações
Pass js variable in html template to google script

I have a .gs file which create a html page:

function doGet() {
  return HtmlService.createHtmlOutputFromFile('index');
}

doGet();
console.log(myvariable);

and in that index.html file I'll create a variable in tag, which I'd like to pass to my .gs file, for further putting it in google spreadsheet.

<script>
  var myvariable = 10;
</script>

Is there any method that can carry out my need?

Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Pass variable to htmltemplate

function elfunko() {
  let t = HtmlService.createTemplate('<input type="text" value="<?= globalvariable ?>" />');
  t.globalvariable = "Hello World";
  SpreadsheetApp.getUi().showModelessDialog(t.evaluate(),'title');
}

enter image description here

Pass variable back to server from html

This one will pass a variable back to server scripts when you click the button on the dialog you can see the result by looking in elfunko1s execution log.

function elfunko() {
  let t = HtmlService.createTemplate('<input type="button" value="<?= globalvariable ?>" onclick="google.script.run.elfunko1({variable:<?= globalvariable ?>})" />');
  t.globalvariable = "Hello World";
  SpreadsheetApp.getUi().showModelessDialog(t.evaluate(),'title');
}

function elfunko1(obj) {
  console.log(JSON.stringify(obj))
}

enter image description here

Cloud logs
Feb 26, 2022, 8:38:00 PM    Debug   {"variable":"Hello World"}

client to server comm

templated html

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