0

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 ? .

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


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

</ul>
<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>
  </select>

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

</div>
</body>

2 Answers 2

0

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.

0

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 .