Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

python - How to populate a dependent select tag in html with sql query?

I am creating a website with Flask and currently have one dropdown filled with a list of regions. I now need to populate a second dropdown dynamically depending on the selection of the first dropdown using an sql query.

I first need to get the 'region_id' from the database using the query 'select region_id from regions where region_name like (region select tag option here)'. Then I use that id to get the plans related to that region using the query 'select wsp_full_name from water_sharing_plans where region_id = (region id from first query here)'. The result of this query should populate the second dropdown.

How can this be done in HTML? Here is my HTML so far..

<html>
<head>
    <title>Form</title>
</head>
<body>

    <label for="regions">Choose a Region:</label>
    <select name="regions" id="regions">
        {% for regions in list_of_regions %}
            <option value={{regions}}>{{regions}}</option>
        {% endfor %}
    </select>
</body>
</html>
question from:https://stackoverflow.com/questions/66056551/how-to-populate-a-dependent-select-tag-in-html-with-sql-query

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...