/    Sign up×
Community /Pin to ProfileBookmark

Compare data inside
with data inside csv file

I would like to preface that I’m more of a database dev guy. I have little to no knowledge in web development.
With that out of the way, here is my question.

Is it possible to lookup the data inside a <div> tag based on class and search if it matches the data in column1 or column 3 of a csv file. For any of the value that matches, show it in table format in html.

`<div id=”highlight” class=highlighter”>
<table>
<tbody>
<tr>
<td> Apple </td>
<td> Orange </td>
…………
</div>
`

**sample_.csv**
Col_1 , Col_2 , Col_3
Apple , Mango , Banana
Banana , Mango , Mango
Mango , Banana , Orange

**output**
Col_1 , Col_2 , Col_3
Apple , Mango , Banana
Mango , Banana , Orange

Hope my question is clear.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumNov 21.2019 — I assume that this csv file is located on the server? If so I would recommend to do the comparison server side. Use PHP's DOMElement class to parse the HTML and get the data inside the list:

https://www.php.net/manual/de/class.domelement.php
Copy linkTweet thisAlerts:
@mbc016authorNov 25.2019 — Would it be possible to do this using javascript alone?
Copy linkTweet thisAlerts:
@SempervivumNov 25.2019 — Is the CSV file located on the server or locally on the users's computer?
Copy linkTweet thisAlerts:
@mbc016authorNov 25.2019 — @Sempervivum#1611146 it is located on the server (same root folder of where the html files are).
Copy linkTweet thisAlerts:
@SempervivumNov 25.2019 — If you don't want to use PHP at all, you will have to load the CSV file by Ajax:

https://api.jquery.com/jquery.ajax/

Then you have to parse the CSV as described here:

https://code.tutsplus.com/tutorials/parsing-a-csv-file-with-javascript--cms-25626?ec_unit=translation-info-language

or by use of this script:

https://github.com/typeiii/jquery-csv
Copy linkTweet thisAlerts:
@SempervivumNov 25.2019 — PS: Unfortunately I don't understand this:
lookup the data inside a <div> tag based on class[/quote]
Should the data to be looked up be the content of the table inside the div? Or should the table contain the required output?
Copy linkTweet thisAlerts:
@SempervivumNov 25.2019 — PS: I forgot about that there is another library that enables for parsing a remote file as you need to:

https://www.papaparse.com/#remote-files
Copy linkTweet thisAlerts:
@mbc016authorNov 25.2019 — @Sempervivum#1611161 You're correct. The data to be looked up is the content of the table inside the div tag.

Thanks for the links you provided. I'll check them out! :)
×

Success!

Help @mbc016 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 4.23,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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