Video 58: Creating a Search Form
This commit is contained in:
parent
9dcb792e18
commit
5c550efba9
@ -1,6 +1,14 @@
|
||||
console.log('Client side javascript file is loaded!')
|
||||
|
||||
fetch('/weather?address=boston').then((response) => {
|
||||
const weatherForm = document.querySelector('form')
|
||||
const search = document.querySelector('input')
|
||||
|
||||
weatherForm.addEventListener('submit', (e) => {
|
||||
e.preventDefault()
|
||||
|
||||
const location = search.value
|
||||
|
||||
fetch('/weather?address=' + location).then((response) => {
|
||||
response.json().then((data) => {
|
||||
if (data.error) {
|
||||
console.log(data.error)
|
||||
@ -10,3 +18,4 @@ fetch('/weather?address=boston').then((response) => {
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -6,16 +6,23 @@
|
||||
<title>Weather</title>
|
||||
<link rel="icon" href="/img/weather.png">
|
||||
<link rel="stylesheet" href="/css/styles.css">
|
||||
<script src="/js/app.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="main-content">
|
||||
{{>header}}
|
||||
|
||||
<p>Use this site to get your weather!</p>
|
||||
|
||||
<form>
|
||||
<input placeholder="Location">
|
||||
<button>Search</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{{>footer}}
|
||||
|
||||
<script src="/js/app.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user