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

243
Visualizações
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
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