43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
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;
|
|
|
|
data.forEach(row => {
|
|
const option = document.createElement('option');
|
|
option.value = row["nazwa"];
|
|
option.textContent = row["nazwa"];
|
|
fuelType.appendChild(option);
|
|
|
|
console.log(row);
|
|
});
|
|
|
|
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");
|
|
}
|
|
});
|
|
|