From 2fbf0bb91d77589f0cd4556cd95e6e220643f636 Mon Sep 17 00:00:00 2001 From: u1 Date: Fri, 8 Nov 2024 14:44:15 +0100 Subject: [PATCH] get ok --- index.html | 2 ++ js/script.js | 80 ++++++++++++++++++++++++---------------------------- 2 files changed, 39 insertions(+), 43 deletions(-) diff --git a/index.html b/index.html index 5fc77b9..771e794 100644 --- a/index.html +++ b/index.html @@ -28,6 +28,8 @@ + + diff --git a/js/script.js b/js/script.js index eb412db..7225a75 100644 --- a/js/script.js +++ b/js/script.js @@ -1,48 +1,42 @@ +const fuelType = document.getElementById('fuel-type'); + +const cena = document.getElementById("cena"); + +let usersData = []; + document.addEventListener('DOMContentLoaded', function() { + fetch('php/gget.php') + .then(response => response.json()) + .then(data => { + usersData = data; - const fuelType= document.getElementById('fuel-type'); + data.forEach(row => { + const option = document.createElement('option'); + option.value = row["nazwa"]; + option.textContent = row["nazwa"]; + fuelType.appendChild(option); - let usersData = []; + console.log(row); + }); - // imieSelect.addEventListener('focus', function() { - - fetch('php/gget.php') - .then(response => response.json()) - .then(data => { - - data.forEach(row => { - - - const option = document.createElement('option'); - option.value = row["nazwa"]; - //option.textContent = dane.imie + " " + dane.nazwisko; - fuelType.appendChild(option); - option.textContent = row["nazwa"]; - console.log (row) - }); - /* - usersData = data; - imieSelect.innerHTML = ""; - data.forEach(dane => { - const option = document.createElement('option'); - option.value = dane.id; - option.textContent = dane.imie + " " + dane.nazwisko; - imieSelect.appendChild(option); - }); -*/ - - console.log(data); - }) - .catch(error => console.error('Error fetching data:', error)); -/* - imieSelect.addEventListener('change', function() { - const selectedId = imieSelect.value; - const selectedPerson = usersData.find(dane => dane.id == selectedId); - if (selectedPerson && selectedPerson.photo) { - photoDisplay.src = 'data:image/jpeg;base64,' + selectedPerson.photo; - } else { - photoDisplay.src = ''; - } - }); -*/ + console.log(data); + }) + .catch(error => console.error('Error fetching data:', error)); }); + +fuelType.addEventListener('change', function() { + console.log("Zmiana wybranego paliwa"); + const selectedId = fuelType.value; + + const selectedFuel = usersData.find(dane => dane.nazwa === selectedId); + + cena.textContent = selectedFuel["cena"]; + console.log("mati"); + if (selectedFuel) { + const cena = selectedFuel.cena; + console.log("Cena wybranego paliwa:", cena); + } else { + console.error("Nie znaleziono ceny dla wybranego paliwa"); + } +}); +