Reputation: 43
How can I empty the 'city' field after click button 'Get Weather'? and I have to click twice to the button to get the correct 'time' image
code link : project link
Upvotes: 0
Views: 63
Reputation: 8418
getWeather = async (e) => {
e.preventDefault();
// const city = e.target.elements.city.value;
const element = e.target.elements.city;
const city = element.value;
// after data fetching or at once
element.value="";
Also read docs about uncontrolled components.
Upvotes: 0
Reputation: 1309
document.getElementById("city").value = ""
--- This will work if it is an input field, or text area.
Upvotes: 1
Reputation: 85
Take a look at this:
<!DOCTYPE html>
<html>
<body>
<p>Enter some text in the fields below,
then press the "Reset form" button to
reset the form.</p>
<form id="myForm">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="button" onclick="submit()" value="Reset form">
</form>
<script>
function submit() {
/*Put all the data posting code here*/
document.getElementById("myForm").reset();
}
</script>
</body>
</html>
Upvotes: 0