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

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

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 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