Проблема в том, что я не могу использовать переменные (firstName, LastName, email и phoneNumber) вместо строки в разделе «значения» в функции выполнения. Всякий раз, когда я нажимаю кнопку «Выполнить», он добавляет строки, такие как «Place_Holder», но когда я ввожу firstName, он не добавляется. Извините за такое длинное объяснение. Это мое первое сообщение здесь.
Код: Выделить всё
googleapi
Information Form
First Name:
Last Name:
Email:
Phone Number:
Submit
document.getElementById("submitButton").addEventListener("click", displayMessage );
function displayMessage() {
var firstName = document.getElementById('firstNameInput').value;
var lastName = document.getElementById('lastNameInput').value;
var email = document.getElementById('emailInput').value;
var phoneNumber = document.getElementById('phoneNumberInput').value;
document.getElementById("submitMessage").innerHTML = "Hello " + firstName + " " + lastName + " your information has been submitted";
}
/**
* Sample JavaScript code for sheets.spreadsheets.values.append
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/spreadsheets"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/sheets/v4/rest")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.sheets.spreadsheets.values.append({
"spreadsheetId": "*removed*",
"range": "A1:D2",
"includeValuesInResponse": "false",
"insertDataOption": "INSERT_ROWS",
"responseDateTimeRenderOption": "SERIAL_NUMBER",
"valueInputOption": "USER_ENTERED",
"resource": {
"values": [
[
"Place_Holder",
"Place_Holder",
"Place_Holder",
"Place_Holder"
]
]
}
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: '*removed*'});
});
authorize and load
execute
`
Подробнее здесь: https://stackoverflow.com/questions/515 ... i-variable