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

235
Views
Jinja2 + JS - How can I retrieve value from a select box using Java script + Jinja2 variable

I have a drop list with its values being populated using Jinja2. I want to fetch the value of the option selected i.e, value="{{car.key.name}}" and print it in the <p> tag below. I tried using javascript, but somehow it is not working on change of options selected.

Html+Jinja side:

<select onchange="val()" id="loop1">
            <option>------</option>
            {% for car in cars %}
            <option value="{{car.key.name}}" name="ev1_key">{{ car.ev_name }}</option>
            {% endfor %}

        </select>
        <p id="car1_key">car1_key</p>

Javascript side:

var selectTag = document.getElementById('loop1')
var pTag = document.getElementById('car1_val')
pTag.innerText = selectTag.value

function val() {
    pTag.innerText = selectTag.value;
    var strTxt = selectTag.options[selectTag.selectedIndex].value;
    pTag.innerHTML = strTxt;
}

Can anyone help me out where did I go wrong?

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!