i have these function on my google script app to generate some button on a table
FYI i have no knowledge of JS, and i just made this with chat GPT
// Function to handle button clicks
function handleButtonClick(rowIndex, colIndex) {
google.script.run.withSuccessHandler(function(response) {
// Do something after button click, if needed
}).handleButtonClick(rowIndex, colIndex);
}
// Function to handle date button clicks
function handleDateButtonClick(rowIndex, colIndex) {
google.script.run.withSuccessHandler(function(response) {
// Do something after date button click, if needed
}).handleDateButtonClick(rowIndex, colIndex);
}
function submitData(client, tanggalDatang, jenisBarang) {
var sheet = SpreadsheetApp.openById('SPREADSHEET_ID').getSheetByName('Utama');
var dataRange = sheet.getDataRange();
var values = dataRange.getValues();
var matchedRowData = '';
var totalFound = 0;
for (var i = 1; i < values.length; i++) {
if (values[i][3] == client && Utilities.formatDate(values[i][1], Session.getScriptTimeZone(), 'dd/MM/yyyy') == tanggalDatang && (jenisBarang === '' || values[i][4] == jenisBarang)) {
totalFound++;
matchedRowData += '<table class="table table-bordered">';
for (var j = 0; j < values[i].length; j++) {
var cellValue = values[i][j];
var orderId = values[i][0];
var trId = orderId + '_' + (j + 1);
if (i === 1) {
matchedRowData += '<tr id="' + trId + '"><th style="width: 30%; font-weight:bold;">' + values[0][j] + '</th><td>' + cellValue + '</td>';
} else {
matchedRowData += '<tr id="' + trId + '"><td style="width: 30%;">' + values[0][j] + '</td><td>' + cellValue + '</td>';
}
if (j >= 13 && j <= 19) {
matchedRowData += '<td style="width: 15%;"><button onclick="handleButtonClick(' + i + ', ' + (j + 1) + ')">Button</button></td>';
} else if (j >= 7 && j <= 9) {
matchedRowData += '<td style="width: 15%;"><button onclick="handleDateButtonClick(' + i + ', ' + (j + 1) + ')">Add Date</button></td>';
}
}
matchedRowData += '</tr></table><br>';
}
}
matchedRowData = '<h3>Data dari <strong>' + client + '</strong> tanggal <strong>' + tanggalDatang + '</strong> - Total: <strong>' + totalFound + '</strong> item </h3>' + matchedRowData;
return matchedRowData;
}
and this is my script on index html to handle that GS
function handleSubmit(event) {
event.preventDefault();
var client = document.getElementById("clientSelect").value;
var tanggalDatang = document.getElementById("tanggalDatangSelect").value;
var jenisBarang = document.getElementById("jenisBarangSelect").value;
google.script.run.withSuccessHandler(function (matchedRowData) {
var matchedRowDiv = document.getElementById("matchedRow");
matchedRowDiv.innerHTML = matchedRowData;
}).submitData(client, tanggalDatang, jenisBarang);
}
// Function to handle button clicks generated by submitData function
function handleButtonClick(rowIndex, colIndex) {
// Implement your logic to handle button clicks here
alert("Button clicked! Row: " + rowIndex + ", Column: " + colIndex);
}
and this is the preview when a button clicked
https://i.stack.imgur.com/Sqgc1.png
as you see when a button clicked , it could read the spreadsheet cell name that i generate inside
but it does not submit anything to my sheet.
the log from browser console is
Uncaught ReferenceError: handleDateButtonClick is not defined
at HTMLButtonElement.onclick (userCodeAppPanel:1:1)
which part is still wrong?
thank you in advance
i tried to make a dummy button to post on designated cell, it worked,
so it wasnt premission issue