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

91
Views
Getting an input value and rerouting to that using flask and js

I have a navbar on my site with a search button:

layout.html: 
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="/">Home</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">

    </ul>
    <form class="form-inline my-2 my-lg-0" id="search-pressed" >
      <input class="form-control mr-sm-2" id="search-text" type="search" placeholder="Search" aria-label="Search">
      <input class="btn btn-outline-success my-2 my-sm-0"  type="submit"></button>
    </form>
  </div>
</nav>

On clicking the #search-text submit button, I want to redirect to the route "/search/<content written in #search-pressed>". How can I get the value of #search-text and redirect to the mentioned route? I am using Flask for the backend, so I would want the following to execute as soon as the submit button on my navbar is clicked:

server.py: 
@app.route('/search/<text>')
def search_name(text=None):
    *do stuff*
    return render_template('search.html',text=text)

So far, I could only get the content written in #search-text, but I don't know how to put it into the route:

layout.js
$(document).ready(function(){
  $( "#search-pressed" ).submit(function( event ) {
      let text = $("#search-text").val()

});
})
about 4 years ago · Juan Pablo Isaza
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!