/    Sign up×
Community /Pin to ProfileBookmark

Help working with arrays. Working script needs a little tweaking.

The code below is working fine. It will grab my data from a CSV file and read each line one at a time and display it in 15 second intervals. Now it working perfect. Someone suggested to me that maybe instead of waiting 15 seconds for the new data to appear.. to just display all the data at once but scroll in a loop the information.

Instead of a per line display I’m trying to get all lines to display. I’m not sure how to go about doing this..Using the console.log I am able to print all lines in the processCsvData function.. But I get stuck there and don’t know how to passes all the fields of every line at once.

So if I have lets say 5 lines of data.. it will display:
data[0][1] data[0][2] data[0][4] data[0][5]
data[1][1] data[1][2] data[1][4] data[1][5]
data[2][1] data[2][2] data[2][4] data[2][5]
data[3][1] data[3][2] data[3][4] data[3][5]
data[4][1] data[4][2] data[4][4] data[4][5]

The CSV file will always need to display field 1, 2, 4, and 5 per line. The number of lines sometimes change.

Any help will be appreciated. Not sure why im having a hard time getting this to work.

using these JS files: jquery and jquery csv

Currently its

[CODE]
function pullCsv() {
var csvData;
csvData = $.ajax({
type: “GET”,
url: “test.CSV”,
dataType: “text”,
cache: false,
success: function (result) {
csvResult = result;
if (csvResult == “”) {
noCsvData();
} else {
processCsvData(csvResult);
}
}
});
};
function processCsvData(csvResult) {
var data = $.csv.toArrays(csvResult);
for (var i = 0; i < data.length; i++) {
printEvents(data, i);
}
setTimeout(function () {
pullCsv();
}, 15000 * data.length);

}

function printEvents(data, idx) {
setTimeout(function () {
document.getElementById(“line1”).innerHTML = data[idx][1];
document.getElementById(“line2”).innerHTML = data[idx][2];
document.getElementById(“line3”).innerHTML = data[idx][4];
document.getElementById(“line4”).innerHTML = data[idx][5];
}, idx * 15000);
}
[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @substancev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...