I've been looking for different solutions on the site, but none seem to work for me.
I need to trigger a submit button with Enter keypress event and mouse click, in order to fetch data from a weather api.
<div class="inputdiv">
<input type="text" placeholder="Enter City, Country" id="cityinput">
<input type="submit" value="Submit" id="add" onclick="">
</div>
<script src="./script.js"></script>
Here's the js:
let inputval = document.querySelector('#cityinput')
let btn = document.getElementById('add')
inputval.addEventListener("keypress", function(event) {
if (event.key === "Enter") {
event.preventDefault();
document.getElementById("add").click();
fetch('......')
When I press Enter it works, but I can't find a way to fetch even clicking the button.