Skip to content

Instantly share code, notes, and snippets.

@Yudhajitadhikary
Created December 17, 2020 05:50
Show Gist options
  • Save Yudhajitadhikary/0a31a334da1c242a7c087f56d9c51157 to your computer and use it in GitHub Desktop.
Save Yudhajitadhikary/0a31a334da1c242a7c087f56d9c51157 to your computer and use it in GitHub Desktop.
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