58. Creating Search Form
Goal : Use input value to get weather
Goal : Use input value to get weather
- Migrate fetch call into the submit callback
- Use the search text as the address query staring value
- Submit the form with a valid and invalid calue to test
const weatherForm = document.querySelector('form')
const search = document.querySelector('input')
weatherForm.addEventListener('submit', (e) => {
e.preventDefault()
const location = search.value
fetch('http://localhost:3000/weather?address=' + location).then((response) => {
response.json().then((data) => {
if (data.error) {
console.log(data.error)
} else {
console.log(data.location)
console.log(data.forecast)
}
})
})
console.log(location)
})