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

246
Views
Node.js/Express how to modify data obtained from checkbox form input

I have a list of input checkbox elements rendered with handlebars

<form method="POST" action='/processImages'>
                        <input type='checkbox' id='.DS_Store' name='.DS_Store' />
                            <p>.DS_Store</p>
                        <input type='checkbox' id='.localized' name='.localized' />
                            <p>.localized</p>
                        <input type='checkbox' id='Courses' name='Courses' />
                            <p>Courses</p>
                        <input type='checkbox' id='Home' name='Home' />
                            <p>Home</p>
                    
<input type="submit" value="run">
         

and i want to pass the names to the other function or render their names on other path With this code:

const processRouter = express.Router()

const processRouter = express.Router()
processRouter.post('/', async (req, res, next) => {
    const test =(req.body) 
    res.send(test)
})

app.use('/processImages', processRouter)

what im getting is:

{"Courses":"on","Home":"on"}

But i want to get just the names like {"Courses", "Home"} How to get rid of this "on" on each element, i'm assuming this is comming from input type checkbox.

I'm a beginner and i cant really understand how i should request only "names". Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It would not be possible to get {"Courses", "Home"} because this is invalid JSON format. You could however pass an array ["Courses", "Home"] through the request instead.

If the request that your form is sending is not something you want - consider writing your own onSubmit function to handle the AJAX call.


Nonetheless, is there a particular reason why you want to modify the request? You could parse the original format to result in what you want:

function iterate(input) {
    //Example input: {"Courses":"on","Home":"on"}

    const arr = [];

    Object.entries(input).forEach(function ([key, value], index) {
        console.log(key, value, index);
        if (value === "on")
            arr.push(key);
    });

    return arr;
}

console.log(iterate({ "Courses": "on", "Home": "on" }));
console.log(iterate({ "Courses": "on", "Home": "off" }));
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!