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

214
Vistas
Submit multiple forms with one button in pug

I'm currently making a quiz application that dynamically serves a user a list of questions with a dropdown to select their answer from using:

    ul
        each val in questions
            li
                div
                    label= val.Question
                    form(method='POST')
                        select(name='questionAnswer')
                            option(value='true') True
                            option(value='false') False

                    button(type="submit") Submit
                

I'm attempting to push these answers into an array to later use for comparing to their correct answer.

let radioAnswers = [];

router.post('/play', function(req, res) { 
  answers.push(req.body.radio)
  console.log(radioAnswers)
})

However it's not too functional having a submit button next to every question, that can be easily broken. How would I go about having one submit button to submit every form?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Put everything in one form and give each question its own name for the input’s name attribute.

form(method='POST')
    ul
        each val in questions
            li
                div
                    label= val.Question
                        select(name=val.Name)
                            option(value='true') True
                            option(value='false') False

    button Submit

Then you use req.body[val.Name] to retrieve the answer for each question on the server.

about 4 years ago · Juan Pablo Isaza Denunciar
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