get ok
This commit is contained in:
parent
fbcb6e8e5a
commit
2fbf0bb91d
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
<select id="fuel-type" name="fuel-type">
|
<select id="fuel-type" name="fuel-type">
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<label id="cena">Calculate ...</label>
|
||||||
|
|
||||||
<label for="liters">Ile litrów?</label>
|
<label for="liters">Ile litrów?</label>
|
||||||
<input type="text" id="liters" name="liters">
|
<input type="text" id="liters" name="liters">
|
||||||
|
|
80
js/script.js
80
js/script.js
|
@ -1,48 +1,42 @@
|
||||||
|
const fuelType = document.getElementById('fuel-type');
|
||||||
|
|
||||||
|
const cena = document.getElementById("cena");
|
||||||
|
|
||||||
|
let usersData = [];
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
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() {
|
console.log(data);
|
||||||
|
})
|
||||||
fetch('php/gget.php')
|
.catch(error => console.error('Error fetching data:', error));
|
||||||
.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 = '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue