I'm making a very simple web UI for a CSV file with the results of a python crawler. The UI needs to display the contents of each row individually in different div tags. The row needs to be selected at random after the user presses a button. this will then display the data selected from the CSV file.
I'm very new to JavaScript although i have some experience with other programming languages.
the code i currently have is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="jquery-1.12.3.min.js" type="text/javascript">
</script>
<title>Untitled Document</title>
<style type="text/css">
body { font-family:arial, helvetica, sans-serif; font-weight:normal; font-size:13px; color:#000; text-align:left; margin:3px 0px; }
#wrap { width:500px; height:500px; margin:20px; }
</style>
</head>
<body>
<button onclick="myFunction()">Click me</button>
<div id="wrap" style="background-color:#666; height:100%; width:100%">
</div><!-- end wrap -->
<script type="text/javascript">
$.get('testResults.csv', function myFunction(data) {
var build = '<table border="1" cellpadding="2" cellspacing="0" style="border-collapse: collapse" width="100%">\n';
var rows = data.split("\n");
rows.forEach( function getvalues(thisRow) {
build += "<tr>\n";
var columns = thisRow.split(",");
for(var i=0;i<columns.length;i++){ build += "<td>" + columns[i] + "</td>\n"; }
})
build += "</table>";
$('#wrap').append(build);
});
</script>
</body>
</html>
I found this particular block of code on the net, and havent been able to get it to output a single row as opposed to the entire CSV file as a table.
Preferably the button (which doesn't work) would run the code parsing each value in the row to an id or class that i can pick up in the HTML(outputting as a table is not needed). as far as specifying certain values, I can write some if statements for that another time.
CSV file here: http://www.filedropper.com/testresults
thanks!