Implementazione form aggiunta
This commit is contained in:
20
add.html
Normal file
20
add.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Aggiungi pizza</title>
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<form id="addForm" onsubmit="handleAddPizza(event)" >
|
||||
<label for="id">ID Pizza</label><br>
|
||||
<input type="number" id="id" name="id" required><br>
|
||||
<label for="name">Nome</label><br>
|
||||
<input type="text" id="name" name="name" required><br>
|
||||
<label for="prezzo">Prezzo</label><br>
|
||||
<input type="number" step="0.01" id="price" name="price" required><br>
|
||||
<input type="submit" value="Aggiungi">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -14,7 +14,7 @@
|
||||
<main>
|
||||
<div class="pageControls">
|
||||
<div>
|
||||
<button onclick="location.href='add.html'">+</button>
|
||||
<button onclick="window.open('add.html', 'popup', 'width=400,height=300')">+</button>
|
||||
<button onclick="listPizze()">Aggiorna</button>
|
||||
<br><br>
|
||||
</div>
|
||||
|
||||
14
script.js
14
script.js
@@ -84,7 +84,7 @@ function editPizza(id){
|
||||
}
|
||||
}
|
||||
|
||||
function addPizza(nome, id, prezzo){
|
||||
function addPizza(id, nome, prezzo){
|
||||
const myHeaders = new Headers();
|
||||
myHeaders.append("Content-Type", "application/json");
|
||||
|
||||
@@ -105,10 +105,20 @@ function addPizza(nome, id, prezzo){
|
||||
.then((response) => response.text())
|
||||
.then((result) => {
|
||||
alert("Pizza aggiunta con successo!");
|
||||
listPizze();
|
||||
window.close();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
alert("Errore nell'aggiunta, controllare la console per dettagli sull'errore.");
|
||||
});
|
||||
}
|
||||
|
||||
function handleAddPizza(event){
|
||||
event.preventDefault();
|
||||
|
||||
const nome = document.getElementById("name").value;
|
||||
const id = document.getElementById("id").value;
|
||||
const prezzo = document.getElementById("price").value;
|
||||
|
||||
addPizza(id, nome, prezzo);
|
||||
}
|
||||
Reference in New Issue
Block a user