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

258
Views
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]});   
    });

});
about 4 years ago · Santiago Trujillo
2 answers
Answer question

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>

about 4 years ago · Santiago Trujillo Report

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>
about 4 years ago · Santiago Trujillo 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!