Skip to content Skip to sidebar Skip to footer

Flask - How To Display A Selected Dropdown Value In Same Html Page?

I am developing a flask application, in which I have a dropdown, when I select an option, it should display below the dropdown 'Your selected score : ' and the selected score. I am

Solution 1:

This should work:

<html><head><scripttype="text/javascript"src="https://code.jquery.com/jquery-2.1.3.min.js"></script><script>
    $(document).ready(function(){
      $('select').on('change', function(){
        $('#result').html('Your score is: ' + $(this).find('option:selected').val());
      });
    });
  </script></head><body><selectname="score">
    {% for score in range(6) %}
    <optionvalue="{{score}}">{{score}}</option>
    {% endfor %}
  </select><divid="result"></div></body></html>

Solution 2:

You need change event fired on select element.

Try,

<selectname="score"onchange="updateSelected(event)">
    {% for score in range(6) %}
    <optionvalue={{score}}> {{score}} </option>
    {% endfor %}
</select><divid="res"></><script>functionupdateSelected(event) {
        document.getElementById('res').innerHTML = 'Your selected score : ' + event.target.value;
    }
</script>

Post a Comment for "Flask - How To Display A Selected Dropdown Value In Same Html Page?"