Skip to content
Snippets Groups Projects
Commit 0ebe89f8 authored by Ruginosu, M.I. (Ioana, Student B-BIT)'s avatar Ruginosu, M.I. (Ioana, Student B-BIT) :ear_tone1:
Browse files

issue#7 solved (update)

parent fbe3e245
No related branches found
No related tags found
No related merge requests found
......@@ -146,3 +146,40 @@ function deletePokemonType() {
});
}
function updatePokemonType() {
let idPokemon = document.getElementById("idUpdate").value;
let nameUpdate = document.getElementById("nameUpdate").value;
let imgUrlUpdate = document.getElementById("url").value;
let pokedexNumberUpdate = document.getElementById("pokedex").value;
let primaryTypeUpdate = document.getElementById("primary").value;
let secondaryTypeUpdate = document.getElementById("secondary").value;
const data = {
id: idPokemon,
name: nameUpdate,
imgUrl: imgUrlUpdate,
pokedexNumber: pokedexNumberUpdate,
primaryType: primaryTypeUpdate,
secondaryType: secondaryTypeUpdate
// Add other fields as needed
};
fetch(`/pokemon/api/pokemonTypes/${idPokemon}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(response => {
if(response.ok) {
updatePokemonTypesTable();
updateDetails(idPokemon);
} else {
console.error('Failed to update Pokemon type:', response.status);
}
}).catch(error => {
console.error('Error updating Pokemon type:', error);
});
}
......@@ -133,6 +133,39 @@
<br>
<br>
<h4>Update Pokemon type</h4>
<form id = "updatePokemonType" onsubmit = "updatePokemonType()">
<div class = "form-group">
<label for = "idUpdate">Pokemon ID</label>
<input type = "text" class = "form-control" id = "idUpdate">
</div>
<div class = "form-group">
<label for = "nameUpdate">Name</label>
<input type = "text" class = "form-control" id = "nameUpdate">
</div>
<div class = "form-group">
<label for = "url">Url</label>
<input type = "text" class = "form-control" id = "url">
</div>
<div class = "form-group">
<label for = "pokedex">Pokedex Number</label>
<input type = "text" class = "form-control" id = "pokedex">
</div>
<div class = "form-group">
<label for = "primary">Primary type</label>
<input type = "text" class = "form-control" id = "primary">
</div>
<div class = "form-group">
<label for = "secondary">Secondary type</label>
<input type = "text" class = "form-control" id = "secondary">
</div>
<button type = "submit" class = "btn btn-primary">Update Pokemon type</button>
</form>
<br>
<br>
<div class="container">
<div class="row">
<div id="tableDiv" class="col-8">No data</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment