This commit is contained in:
u1 2024-11-08 14:44:15 +01:00
parent fbcb6e8e5a
commit 2fbf0bb91d
2 changed files with 39 additions and 43 deletions

View File

@ -29,6 +29,8 @@
<select id="fuel-type" name="fuel-type">
</select>
<label id="cena">Calculate ...</label>
<label for="liters">Ile litrów?</label>
<input type="text" id="liters" name="liters">

View File

@ -1,48 +1,42 @@
const fuelType = document.getElementById('fuel-type');
const cena = document.getElementById("cena");
let usersData = [];
document.addEventListener('DOMContentLoaded', function() {
const fuelType= document.getElementById('fuel-type');
let usersData = [];
// imieSelect.addEventListener('focus', 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 = dane.imie + " " + dane.nazwisko;
fuelType.appendChild(option);
option.textContent = row["nazwa"];
console.log (row)
fuelType.appendChild(option);
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 = '';
}
});
*/
});
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");
}
});