/    Sign up×
Community /Pin to ProfileBookmark

Pulling Data from a CSV File

So I’m completely lost on this. I’ve searched google with little luck. Is it even possible? I’m trying to get data from the thirteenth value of every row of a CSV file and put the results in a text box. I’ve already wasted time doing this in php only to realize I need to do it client-side if I want to get good results. Any help would be appreciated.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERApr 18.2007 — Assuming the following:

1. The CSV file format is seperated by "n" for each row

2. There are no extra ',' characters seperating the fields in each row.

Can you try this?

var CSVarr = CSVfile_text.split("n");

var textbox_text = '';

for (var i=0; i<CSVarr.length; i++) {

CSVrow = CSVarr[i].split(",");

textbox_text += CSVrow[12]+','; // 13th element of array

}

alert(textbox_text);
Copy linkTweet thisAlerts:
@mrhooApr 18.2007 — php is a champ at handling csv files, it lets you open a file as an array of lines, and then explode each line into an array of values.

You can do the same thing in javascript using the responseText from an AJAX GET request, but you'll need to write your own functions for splitting the file into rows and columns. And the result won't be accessible or search indexed, if that makes a difference. It does allow you the ability to add content to an open page, and it can be worth doing, but write the php first.

Once you do that you will better see the logic needed for the javascript, and you can decide then if it is worth your time to implement.
×

Success!

Help @jingles 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...