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

222
Visualizações
Syntax error in defining a button in the Google Apps Script Javascript

I have an error in defining a command button in Google Apps Script. My statement is this, but there are syntax errors that I cannot resolve. Thanks for your help.

str = str + '<td><button onclick=' + 'google.script.run.setApproved(' + '"<?= outputHandle[i][0] ?>"' + ')' + 'id="ldap">' + "Approve" + '</button>'
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I thought that when I saw your script of str = str + '<td><button onclick=' + 'google.script.run.setApproved(' + '"<?= outputHandle[i][0] ?>"' + ')' + 'id="ldap">' + "Approve" + '</button>', it might be required to add a space between )i. So how about the following modification?

Modified script:

str = str + '<td><button onclick=' + 'google.script.run.setApproved(' + '"<?= outputHandle[i][0] ?>"' + ')' + ' id="ldap">' + "Approve" + '</button>'

or

str += '<td><button onclick=' + 'google.script.run.setApproved(' + '"<?= outputHandle[i][0] ?>"' + ')' + ' id="ldap">' + "Approve" + '</button>'

I can confirm that the above modification can be worked. And also, you can modify as follows.

str += '<td><button onclick="google.script.run.setApproved(\'<?= outputHandle[i][0] ?>\')" id="ldap">Approve</button>';
  • I added to ' id="ldap">'. It's from 'id="ldap">' to ' id="ldap">'.
  • From your script of '"<?= outputHandle[i][0] ?>"', it supposes that the value is string. Please be careful this.

Added:

And, when I saw your current script, I could understand your current issue of Uncaught SyntaxError: Unexpected token '<'. Unfortunately, your following script

str += '<td><button onclick="google.script.run.setApproved(<?= outputHandle[i][0] ?>)" id="ldap">Approve</button>';

cannot be used as the template. Because in your script, after the HTML data was loaded, the value is given to the above script by outputHandle of function onSuccess(outputHandle) {,,,}. So in this case, the scriptlet is not required to be used. I thought that this might be the reason for your current issue of Uncaught SyntaxError: Unexpected token '<'. In this case, please modify the above script as follows.

str += '<td><button onclick="google.script.run.setApproved(' + outputHandle[i][0] + ')" id="ldap">Approve</button>';

or

str += `<td><button onclick="google.script.run.setApproved(${outputHandle[i][0]})" id="ldap">Approve</button>`;
  • In this case, when the value of outputHandle[i][0] is the number value, the above modification can be used. But if the value of outputHandle[i][0] is the string value, please modify it as follows. Please be careful this.

      str += `<td><button onclick="google.script.run.setApproved('${outputHandle[i][0]}')" id="ldap">Approve</button>`;
    
about 4 years ago · Santiago Gelvez 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