javascript - Fill div content with array row data, selected by button click - only returning last row -


i have stripped page of bells , whistles try , work - have 5 buttons , div. page reads in rows of data google spreadsheet , populates array data[].

<html> <head>  <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript">    google.load('visualization', '1', {'packages': ['table']});   var i, j, x, k;   var data = new array();   var headers = new array();   var numrows, numcols;    function onldquery() {      var url = 'http://spreadsheets.google.com/tq?key=xxxxxx&pub=0', query = new google.visualization.query(url);      query.setquery('select * b != "" , v> 0 order v desc limit 20');     query.send(handleonldresponse);   }    function handleonldresponse(response) {     if (response.iserror()) {       alert('error in query: ' + response.getmessage() + ' ' + response.getdetailedmessage());        return;     }      numrows = response.getdatatable().getnumberofrows();     numcols = response.getdatatable().getnumberofcolumns();      console.log(numrows);     (i = 0; < numrows; i++) {       (j = 0; j < numcols; j++) {         headers[j] = response.getdatatable().getcolumnlabel(j);         data[i,j] = response.getdatatable().getvalue(i, j);         console.log(data[i,j]);       }     }      loaddata(0);   }    function loaddata(x) {     console.log(x);     console.log(data[x,1]);     console.log(numcols);      $('#test_card').html("");      (k = 0; k < numcols;k++) {       $('#test_card').html($('#test_card').html() + data[x,k] + "<br>");     }   }  </script> </head>  <body onload="onldquery()"> <button id="btn1" onclick="loaddata(1);">1</button> <button id="btn2" onclick="loaddata(2);">2</button> <button id="btn3" onclick="loaddata(3);">3</button> <button id="btn4" onclick="loaddata(4);">4</button> <button id="btn5" onclick="loaddata(5);">5</button>  <div id="test_card">  </div>  </body> </html> 

it loads data correctly data[] array, based on console dump, cannot work out why load last line of data array when a: loading page, , b: trying load different row div clicking on 1 of buttons.

try using .append()

$('#test_card').append(data[x,k] + "<br>"); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -