I'm setting up a new project in python ,and want to setting up a web pageresturant.html using FLASK , this code in html get the selected value from drop down box when button is clicked ,how can i pass this value to python ? .

  function getSelectedValue()
    var selectedValue=document.getElementById("list").value; 
    <!-- need to pass this value -->

  <li><a href="#home">Home</a></li>

<img src="https://i.ytimg.com/vi/5CfJ2VRZuy0/maxresdefault.jpg" alt="Paris" width="1362" height="300">
<form >
<div class="custom-select" style="width:200px;">
  <select id="list">
    <option value="0"></option>
    <option value="KFC">KFC</option>
    <option value="pizza hut">pizza hut</option>
    <option value="spectra">spectra</option>
    <option value="macdonalds">macdonalds</option>

<button class="button2" onclick="getSelectedValue()">Visualization Data </button>


2 Answers 2


The keyword here is AJAX (asynchronous Javascript and XML, don't take the XML too seriously, was hyped at the time the name was coined), you'd want to create a kind of REST API. Take finance problem's /check route as an example, the data passed can be much more complex.


You can give a name-value to the select, give the form tag with the action and method attributes, submit the values via post methods and to the route you build in flask. Then, use the route you built-in and use the request.form.get(name of the select menu) to manipulate the submitted value

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .