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

264
Vistas
How to use <a> instead of a button on express.js post?

I am using handlebars as my templating engine and I use buttons to call app.post() on my javascript file.

<form method="POST" action="/smo_assessment">
<div class="container" id="div1">
    <h3 id="header" align="center">Request Inventory</h3>
    <h4 style="color: white">Select the ID of the request you want to make an assesssment</h4>

    <table>
    <td>
        <select class="form-control" style="width: 80px" name="requestID">
            {{#each requests}}
            <option>{{this.id}}</option>
            {{/each}}
        </select>
    </td>
    <td>
        <button buttontype="submit" class="btn btn-default" id=btn1>Make Assessment</button>
    </td>
    </table>
</form>

However, since I am using bootstrap navbar, I need to use a <a> tag instead of a button in order to navigate to a different page.

app.post('/smo_assessment', urlencodedParser, function(req, res){
    connection.query('SELECT * FROM requests WHERE id=?', req.body.requestID, function(err, rows, fields){
        if(err)
            throw err;
        else 
            selectedRequest = rows  

        res.render('smo_assessment', {assessmentType, data: selectedRequest[0]});   
    });

});
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Try the form.submit() Javascript method:

<form id="theForm" method="POST" action="/smo_assessment">
<div class="container" id="div1">
    <h3 id="header" align="center">Request Inventory</h3>
    <h4 style="color: white">Select the ID of the request you want to make an assesssment</h4>

    <table>
    <td>
        <select class="form-control" style="width: 80px" name="requestID">
            {{#each requests}}
            <option>{{this.id}}</option>
            {{/each}}
        </select>
    </td>
    <td>
        <a href="javascript:document.getElementById('theForm').submit();" class="linkSubmit" id="linkBtn1">Make Assessment</a>
    </td>
    </table>
</form>

over 4 years ago · Santiago Trujillo Denunciar

0

Add an id to your form and use it into a on-click event:

<form id="myForm">
  ...
  <a class="btn btn-default" onclick="myForm.submit();">Make Assessment</a>
</form>
over 4 years ago · Santiago Trujillo 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