I have a Flask backend with MySQL and need to pull values from a table to display in a dropdown.
I have a table with single values like Banana, Apple, Orange, etc.
Inside my html code, the option shows up if a user selects another dropdown (which is hard-coded) so the code looks like this:
$(function() {
$("#inputType").change(function() {
var myform = "<div id=\"newForm\">"
+"<label for=\"inputFruit\">Fruit:</label>"
+"<select class=\"form-control\" id=\"inputFruit\" required>"
+"<option></option>"
+"</select>"
if ($("#inputType").val() == "fruits") {
$(myform).insertBefore("#btnSignUp");
} else {
$("#newForm").remove();
}
Inside my flask app:
@app.route('/getFruits') # gets my fruits as a list and returns
Where do I add code so that the values I get from /getFruits is put into the option in the HTML?