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>'
CodePudding user response:
Consider using backquotes for better readability:
str = `
<td>
<button
onclick="google.script.run.setApproved('"<?= outputHandle[i][0] ?>"')"
id="ldap"
>
Approve
</button>
</td>
`
CodePudding user response:
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.
