Created
December 17, 2020 05:50
-
-
Save Yudhajitadhikary/0a31a334da1c242a7c087f56d9c51157 to your computer and use it in GitHub Desktop.
This file contains 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.querySelector('form'); | |
const name=document.querySelector('#name'); | |
const cost=document.querySelector('#cost'); | |
const error=document.querySelector('#error'); | |
form.addEventListener('submit',(e)=>{ | |
e.preventDefault() | |
if(name.value && cost.value){ | |
const item={ | |
name:name.value, | |
cost:parseInt(cost.value) | |
} | |
db.collection('expenses').add(item).then(res=>{ | |
error.textContent=""; | |
name.value=""; | |
cost.value=""; | |
}) | |
} | |
else{ | |
error.textContent="Please enter values before submitting" | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment