Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbanz authored Aug 9, 2023
1 parent 00fe778 commit b30c882
Showing 1 changed file with 0 additions and 54 deletions.
54 changes: 0 additions & 54 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,61 +208,7 @@ <h2 class="header-text">ɢʟɪᴛᴄʜ-ɢᴀᴅɢᴇᴛꜱ</h1>
<article class="about active" data-page="about">


<script>
function showResult(str) {
if (str.length === 0) {
document.getElementById("livesearch").innerHTML = "";
document.getElementById("livesearch").style.border = "0px";
return;
}

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
displayResults(this.responseXML, str);
}
};
xhttp.open("GET", "products.xml", true);
xhttp.send();
}

function displayResults(xml, searchStr) {
var livesearchDiv = document.getElementById("livesearch");
livesearchDiv.innerHTML = "";

var products = xml.getElementsByTagName("product");
for (var i = 0; i < products.length; i++) {
var title = products[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;
var description = products[i].getElementsByTagName("description")[0].childNodes[0].nodeValue;
var image = products[i].getElementsByTagName("image")[0].childNodes[0].nodeValue;

if (title.toLowerCase().includes(searchStr.toLowerCase())) {
var resultItem = document.createElement("div");
resultItem.className = "result-item";

var imgElement = document.createElement("img");
imgElement.src = image;
imgElement.alt = title;

var titleElement = document.createElement("h3");
titleElement.textContent = title;

var descriptionElement = document.createElement("p");
descriptionElement.textContent = description;

resultItem.appendChild(imgElement);
resultItem.appendChild(titleElement);
resultItem.appendChild(descriptionElement);

livesearchDiv.appendChild(resultItem);
}
}

if (livesearchDiv.innerHTML === "") {
livesearchDiv.innerHTML = "No results found.";
}
}
</script>
<style>
.result-item {
border: 1px solid #A5ACB2;
Expand Down

0 comments on commit b30c882

Please sign in to comment.