Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joypan1 committed Feb 26, 2024
2 parents aeda99d + 9fa6aac commit 68d9d80
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 56 deletions.
9 changes: 3 additions & 6 deletions pages/teamdetails.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
});
}
</script>



</head>
<body>

Expand All @@ -43,7 +40,7 @@ <h1> Team Details </h1>
<br>

<!-- <div id="team-details"> -->
<form id="dataForm" class="teaminfo">
<!-- <form id="dataForm" class="teaminfo"> -->
<label for="teamname"> Name: </label>
<input type="text" id="teamname" name="teamname">

Expand All @@ -52,7 +49,7 @@ <h1> Team Details </h1>
<label for="teamnumber"> Team Number: </label>
<input type="text" id="teamnumber" name="teamnumber" maxlength="4">


<br>

<label for="teamschool"> Based In: </label>
Expand All @@ -63,7 +60,7 @@ <h1> Team Details </h1>
<label for="moreinfo"> More Info: </label><br>
<textarea id="moreinfo" name="moreinfo" rows="8" cols="50" placeholder="big fat textbox" style="resize: none;"></textarea>

</form>
<!-- </form> -->
<!-- </div> -->

<br>
Expand Down
100 changes: 50 additions & 50 deletions pages/teamdetails.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
document.addEventListener('DOMContentLoaded', async () => {
const urlParams = new URLSearchParams(window.location.search);
const id = urlParams.get('id');
// document.addEventListener('DOMContentLoaded', async () => {
// const urlParams = new URLSearchParams(window.location.search);
// const id = urlParams.get('id');

const nameInput = document.getElementById('teamnumber');
const emailInput = document.getElementById('email');
// const nameInput = document.getElementById('teamnumber');
// const emailInput = document.getElementById('email');

// Check if ID exists, if yes, populate the form fields
if (id) {
try {
const response = await fetch(`/getData?id=${id}`);
const data = await response.json();
// // Check if ID exists, if yes, populate the form fields
// if (id) {
// try {
// const response = await fetch(`/getData?id=${id}`);
// const data = await response.json();

// Populate the form fields with existing data
nameInput.value = data.teamnumber || '';
emailInput.value = data.email || '';
} catch (error) {
console.error('Error fetching data:', error);
}
}
// // Populate the form fields with existing data
// nameInput.value = data.teamnumber || '';
// emailInput.value = data.email || '';
// } catch (error) {
// console.error('Error fetching data:', error);
// }
// }

const form = document.getElementById('dataForm');
form.addEventListener('submit', async (event) => {
event.preventDefault();
// const form = document.getElementById('dataForm');
// form.addEventListener('submit', async (event) => {
// event.preventDefault();

const formData = {
name: nameInput.value,
email: emailInput.value
};
// const formData = {
// name: nameInput.value,
// email: emailInput.value
// };

try {
// Handle submitting new information
// Here you can send the formData to your server
console.log('Submitting data:', formData);
// try {
// // Handle submitting new information
// // Here you can send the formData to your server
// console.log('Submitting data:', formData);

// Optionally, you can also save the submitted data to IndexedDB
// This ensures that the form is pre-filled the next time it's accessed with the same ID
await saveDataToIndexedDB(formData, id);
// // Optionally, you can also save the submitted data to IndexedDB
// // This ensures that the form is pre-filled the next time it's accessed with the same ID
// await saveDataToIndexedDB(formData, id);

// Reset the form after submission
form.reset();
} catch (error) {
console.error('Error submitting data:', error);
}
});
});
// // Reset the form after submission
// form.reset();
// } catch (error) {
// console.error('Error submitting data:', error);
// }
// });
// });

async function saveDataToIndexedDB(data, id) {
const db = await openDB('myIndexedDB', 1);
const tx = db.transaction('storeName', 'readwrite');
const store = tx.objectStore('storeName');
// async function saveDataToIndexedDB(data, id) {
// const db = await openDB('myIndexedDB', 1);
// const tx = db.transaction('storeName', 'readwrite');
// const store = tx.objectStore('storeName');

// If an ID exists, update existing data; otherwise, add new data
if (id) {
await store.put(data, id);
} else {
await store.add(data);
}
// // If an ID exists, update existing data; otherwise, add new data
// if (id) {
// await store.put(data, id);
// } else {
// await store.add(data);
// }

await tx.done;
}
// await tx.done;
// }


/* function submitform() {
Expand Down

0 comments on commit 68d9d80

Please sign in to comment.