Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda