Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
Does not clear the form when Post fails

I am trying to Post a form. When Post is successful the form gets cleared. However in case Post fails I don't want to clear the form. How should I update below code so form doesn't clear in case Post fails?

*const form = document.querySelector("#create-form")
const foodName = document.querySelector("#create-name")
const carbs = document.querySelector("#create-carbs")
const protein = document.querySelector("#create-protein")
const fat = document.querySelector("#create-fat")

form.addEventListener("submit", event => {
event.preventDefault()
//console.log(carbs.value)
const operation = async (name,carbs, protein, fat) =>{
const response = await fetch("https://firestore.googleapis.com/v1/projects/jsdemo-3f387/databases/(default)/documents/random12345610",{
method: "POST",
body: JSON.stringify({
fields: {
    name: { stringValue: name },
    carbs: { integerValue: carbs },
    protein: { integerValue: protein },
    fat: { integerValue: fat }
  }
})
})
try{
const data = await response.json()}
catch(error){return;}
}
operation(foodName.value, carbs.value, protein.value, fat.value)

foodName.value = "";
    carbs.value = "";
    protein.value = "";
    fat.value = "";
})*
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!