Created
December 13, 2025 18:29
-
-
Save davidystephenson/9bab4617f1a4c8cbd66bad3a6631eb8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const form = document.getElementById('productForm') | |
| form.addEventListener('submit', async (event) => { | |
| event.preventDefault() | |
| const name = document.getElementById('pname') | |
| const price = document.getElementById('price') | |
| const units = document.getElementById('units') | |
| const description = document.getElementById('desc') | |
| const isAvailable = document.getElementById('instock') | |
| const category = document.getElementById('category') | |
| const image = document.getElementById('prodimg') | |
| const data = { | |
| name: name.value, | |
| price: price.value, | |
| quantity: units.value, | |
| description: description.value, | |
| isAvailable: isAvailable.checked | |
| ? 'Yes' | |
| : 'No', | |
| category: category.value, | |
| image: image.value | |
| } | |
| const body = JSON.stringify(data) | |
| const init = { | |
| method: 'POST', | |
| body | |
| } | |
| await fetch('http://localhost:3000/products', init) | |
| form.reset() | |
| window.location.href = './list_products.html' | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment