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

102
Vistas
Maintain checkbox status in MongoDB

I have a form where users enter data that includes a request for more information. This data is stored in a MongoDB database. Administrators can view each entry in a table on a separate page called list-applicants.html, with a checkbox in the last column of every row that can mark the request as 'complete' for each row/entry. The problem I run into is that checkbox is not being stored in the database.

Data is first stored in a POST routine in my server.js file.

app.post('/api/applicants', async (req, res) => {
    console.log('You posted from a form!');
    console.log(req.body);

    const data = { ...req.body, dateOfApplication: new Date() };

    const collection = client.db("applications").collection("applicants");
    try {
        await collection.insertOne(data);
    } catch (error) {
        console.log(error.message);
    }
    res.status(201);
    res.redirect('/list-applicants.html');
});

In my list-applicants.html file I have the following:

async function getAllApplicants() {
    const response = await fetch('/api/applicants');
    const data = await response.json();

    const { MongoClient, ServerApiVersion } = require('mongodb');
    const dburi = process.env.DATABASE_URI;
    const client = new MongoClient(dburi, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });

    const tableContent = document.getElementById('table-content');

    for (const applicant of data) {
        tableContent.innerHTML += `
            <tr>
                <td>${applicant.fname}</td>
                <td>${applicant.lname}</td>
                <td>${applicant.email}</td>
                <td>${applicant.phone}</td>
                <td>${applicant.campus}</td>
                <td>${applicant.request}</td>
                <td>${applicant.dateOfAttendance}</td>
                <td><input type="checkbox" id="requestComplete" value="complete"></td>
            </tr>
        `
    }
}

I understand I need to somehow do a POST to the MongoDB from the list-applicants.html file. I am just not quite sure how to do that in my list-applicants.js file.

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