-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript2.js
45 lines (38 loc) · 1.47 KB
/
script2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Define your CSV data as an array of objects (simulating a CSV file)
var csvData = [
{ name: "John", attribute1: "Value1", attribute2: "Value2" },
{ name: "Jane", attribute1: "Value3", attribute2: "Value4" },
// Add more rows as needed
];
function searchCSV() {
var search = document.getElementById("search").value.toLowerCase();
var results = [];
for (var i = 0; i < csvData.length; i++) {
if (csvData[i].name.toLowerCase().includes(search)) {
results.push(csvData[i]);
}
}
displayResults(results);
// Update the percentage display
updatePercentage(results.length, csvData.length);
}
function displayResults(results) {
var resultsDiv = document.getElementById("results");
resultsDiv.innerHTML = "";
if (results.length === 0) {
resultsDiv.innerHTML = "No results found.";
} else {
for (var i = 0; i < results.length; i++) {
var result = results[i];
var resultString = "Name: " + result.name + "<br>";
resultString += "Attribute1: " + result.attribute1 + "<br>";
resultString += "Attribute2: " + result.attribute2 + "<br><hr>";
resultsDiv.innerHTML += resultString;
}
}
}
function updatePercentage(matchCount, totalCount) {
var percentageElement = document.getElementById("percentage");
var percentage = ((matchCount / totalCount) * 100).toFixed(2) + "%";
percentageElement.textContent = "Results: " + percentage;
}