2024-11-08 13:44:15 +00:00
|
|
|
const fuelType = document.getElementById('fuel-type');
|
|
|
|
|
|
|
|
const cena = document.getElementById("cena");
|
|
|
|
|
|
|
|
let usersData = [];
|
|
|
|
|
2024-11-13 13:47:17 +00:00
|
|
|
|
2024-11-08 11:41:12 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
2024-11-08 13:44:15 +00:00
|
|
|
fetch('php/gget.php')
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
usersData = data;
|
|
|
|
|
|
|
|
data.forEach(row => {
|
|
|
|
const option = document.createElement('option');
|
|
|
|
option.value = row["nazwa"];
|
|
|
|
option.textContent = row["nazwa"];
|
|
|
|
fuelType.appendChild(option);
|
|
|
|
|
|
|
|
console.log(row);
|
|
|
|
});
|
2024-11-08 11:41:12 +00:00
|
|
|
|
2024-11-08 13:44:15 +00:00
|
|
|
console.log(data);
|
|
|
|
})
|
|
|
|
.catch(error => console.error('Error fetching data:', error));
|
2024-11-08 11:41:12 +00:00
|
|
|
});
|
2024-11-08 13:44:15 +00:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-11-13 13:47:17 +00:00
|
|
|
document.getElementById("oblicz").addEventListener("click", () => {
|
|
|
|
const ile_litrow = document.getElementById("ile_litrow").value
|
|
|
|
const cena_paliwa = document.getElementById("cena").innerHTML
|
|
|
|
console.log(ile_litrow)
|
|
|
|
console.log(cena_paliwa)
|
|
|
|
|
|
|
|
const wynik = ile_litrow * cena_paliwa
|
|
|
|
|
|
|
|
console.log(wynik)
|
|
|
|
|
|
|
|
document.getElementById("wynik").innerHTML = wynik
|
|
|
|
})
|