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?