jquery - Reading in a local csv file in javascript? -


[edit] solved problem using d3, nevermind thanks!

so have csv file looks this, , need import local csv file client side javascript:

    "l.name", "f.name", "gender", "school type", "subjects"     "doe",    "john",  "m",      "university",  "chem i, statistics, english, anatomy"     "tan",    "betty",   "f",     "high school", "algebra i, chem i, english 101"     "han",    "anna",    "f",     "university",  "phy 3, calc 2, anatomy i, spanish 101"     "hawk",   "alan",    "m",     "university",  "english 101, chem i"  

i need parse , output like:

chem i: 3         (number of people taking each subject) spanish 101: 1  philosophy 204: 0  

but now, stuck on importing javascript.

my current code looks this:

<!doctype html>   <html>   <body> <h1>title!</h1> <p>please enter subject(s) wish search for:</p> <input id="numb" type="text"/>  <button onclick="myfunction()">click me see! :) </button> <script> function myfunction() {     var splitresearcharea = [];      var textinput = document.getelementbyid('numb').value;      var splittextinput = textinput.split(",");    for(var =0; i<splittextinput.length; i++) {     var spltresearcharea = splittextinput[i];     splitresearcharea.push(spltresearcharea);   } } 

i've researched , found helpful links on stackoverflow this, this, , this i'm new javascript , don't understand it. should use ajax? filereader? jquery? benefits of using 1 on other? , how implement in code?

but yeah, i'm confused since i'm new javascript, in right direction great. thank you!!

here how use readasbinarystring() filereader api load local file.

<p>select local csv file:</p> <input id="csv" type="file">  <output id="out">     file contents appear here </output> 

basically, need listen change event in <input type="file"> , call readfile function.

var fileinput = document.getelementbyid("csv"),      readfile = function () {         var reader = new filereader();         reader.onload = function () {             document.getelementbyid('out').innerhtml = reader.result;         };         // start reading file. when done, calls onload event defined above.         reader.readasbinarystring(fileinput.files[0]);     };  fileinput.addeventlistener('change', readfile); 

jsfiddle


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -