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

213
Views
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 answers
Answer question

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 Report
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!