Skip to content
Snippets Groups Projects
Commit 1528bd2d authored by chrisb-3's avatar chrisb-3
Browse files

button to add new trainers with name

parent 487d7aff
Branches issue#1
No related tags found
No related merge requests found
package nl.utwente.mod4.pokemon;
public interface createTrainer {
}
package nl.utwente.mod4.pokemon;
public interface updateInterface {
}
......@@ -37,7 +37,7 @@ function updateDetailsTrainer(trainerId) {
<div class="card-body">
<p class="card-text">
Name: ${pt.name} </br>
Aditional Infor: bla bla bla
Aditional Information: bla bla bla
</p>
</div>
</div>
......@@ -109,4 +109,37 @@ function createTrainersTable() {
</tbody>
</table>
`
}
\ No newline at end of file
}
function addTrainer(){
const tableParent = document.getElementById(tableParentId);
tableParent.innerHTML = `
<form id="newTrainerForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<button type="submit" id="submitButton">Submit</button>
</form>
`;
document.getElementById("newTrainerForm").addEventListener("submit", function (event){
event.preventDefault();
const nameInput = document.getElementById("name").value.trim();
if (nameInput) {
const data = { name: nameInput };
fetch('/pokemon/api/trainers', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(res => res.json())
.then(() => {
location.reload();
})
.catch(error => {
console.error('Error adding trainer:', error);
// Optionally, you can display an error message to the user
});
}
});
}
......@@ -12,7 +12,6 @@
<link rel="icon" type="image/x-icon" href="/pokemon/favicon.ico"> <!--mall icon that appears next to the website's title in the browser tab or bookmark bar -->
</head>
<body>
<script src="js/requests.js"></script>
<script>
tableParentId = "tableDiv";
......@@ -30,8 +29,8 @@
});
</script>
<h1>Trainers</h1>
<h1>Trainers </h1>
<button id = "addTrainersButton" class="btn btn-primary" onclick=addTrainer()>Add trainer</button>
<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