Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

271
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda