fetch.get -> html.select ok

This commit is contained in:
u1 2024-11-08 13:45:00 +01:00
parent fbe9a069b6
commit fbcb6e8e5a
3 changed files with 69 additions and 13 deletions

37
@ Normal file
View File

@ -0,0 +1,37 @@
document.addEventListener('DOMContentLoaded', function() {
//const imieSelect = document.getElementById('imie');
let usersData = [];
imieSelect.addEventListener('focus', function() {
fetch('php/gget.php')
.then(response => response.json())
.then(data => {
/*
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 = '';
}
});
*/
});

View File

@ -5,6 +5,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Całodobowa stacja paliw</title> <title>Całodobowa stacja paliw</title>
<link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="css/style.css">
<script type="module" src="js/script.js"></script>
</head> </head>
<body> <body>
<div class="header"> <div class="header">
@ -19,15 +22,19 @@
<div class="main-content"> <div class="main-content">
<div class="form-container"> <div class="form-container">
<h2>Orientacyjny koszt paliwa</h2> <h2>Orientacyjny koszt paliwa</h2>
<form action="obliczenia.html" method="POST"> <form action="obliczenia.html" method="POST">
<label for="fuel-type">Rodzaj paliwa (1-benzyna, 2-olej napędowy):</label> <label for="fuel-type">Rodzaj paliwa:</label>
<input type="text" id="fuel-type" name="fuel-type">
<select id="fuel-type" name="fuel-type">
</select>
<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">
<input type="submit" value="OBLICZ"> <input type="submit" value="OBLICZ">
</form> </form>
</div> </div>
<div class="car-image"> <div class="car-image">
<img src="imgs/samochod.jpg" alt="Car"> <img src="imgs/samochod.jpg" alt="Car">

View File

@ -1,13 +1,25 @@
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
//const imieSelect = document.getElementById('imie'); const fuelType= document.getElementById('fuel-type');
let usersData = []; let usersData = [];
imieSelect.addEventListener('focus', function() { // imieSelect.addEventListener('focus', function() {
fetch('get.php')
fetch('php/gget.php')
.then(response => response.json()) .then(response => response.json())
.then(data => { .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; usersData = data;
imieSelect.innerHTML = ""; imieSelect.innerHTML = "";
@ -19,9 +31,9 @@ document.addEventListener('DOMContentLoaded', function() {
}); });
*/ */
console.log(data);
}) })
.catch(error => console.error('Error fetching data:', error)); .catch(error => console.error('Error fetching data:', error));
});
/* /*
imieSelect.addEventListener('change', function() { imieSelect.addEventListener('change', function() {
const selectedId = imieSelect.value; const selectedId = imieSelect.value;