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

134
Vistas
JavaScript not returning Google Sheets Cell Value

In this code I have declared a variable to get cell value from some spreadsheet owned by me.

And then I used that variable for innerHtml of

element with id "value".

But the web page is not showing any result.

It gives blank page ..

Any idea, what where went wrong ..?

<!DOCTYPE html> 
<html>
<head>
<title>Getting Values from Sheets</title>
</head>
<body>


<p id="value2">Hello World</p>

<p id="value"></p>

<script src="sheets/snippets/snippets.js">

gapi.client.sheets.spreadsheets.values.get({
  spreadsheetId: 1jH0y-PknkZXH7KqjPBWDv98kkBnndGt_GIbdUh_1nRM,
  range: Users!A2
}).then((response) => {
  var result = response.result;
  var numRows = result.values ? result.values.length : 0;
  console.log(`${numRows} rows retrieved.`);
document.getElementById("value").innerHTML = result;
});
</script>

</body>

</html>

Thank You

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Set the value at the time of receiving the response.

gapi.client.sheets.spreadsheets.values.get({
  spreadsheetId: 1jH0y-PknkZXH7KqjPBWDv98kkBnndGt_GIbdUh_1nRM,
  range: users!a2
}).then((response) => {
  var result = response.result;
  var numRows = result.values ? result.values.length : 0;
  console.log(`${numRows} rows retrieved.`);
  document.getElementById("value").innerHTML = result;
});

This is because the next task is executed after sending a request to perform an asynchronous task.

document.getElementById("value").innerHTML = result; code was outside of then().

The var result is not defined at this moment.

about 4 years ago · Juan Pablo Isaza 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