Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!