Your question shows some misunderstanding on how web applications work.
The user has to type an address in a browser to get to the application. That sends a request to the server. The server code (written in python) receives this request and has the opportunity to send an answer. The answer is a document usually written in HTML. Some parts of this document can be dynamic, i.e. generated by the python code. Other parts of the document can be static. The browser then renders the document on the user window.
After that, the only single way your python code can know about something that happens on the browser window, or to run any part of the python code, is to make the browser send another request.
That can happen in many situations, the most common being:
- User clicks on a link to another
url, making browser send another
request to this new url.
- User clicks on
submit
button, making
browser submit the form as a request
to the address configured in the
form's action
attribute.
- Some code in the actual page, usually written in ECMAscript (also known as javascript), makes a request under the hood.
The latter is what you want. You must write in javascript some code to make the browser send the information choosen in the drop down to the server. That way your python code on the server can do something about it.
The simple way to do that is by making the onchange
event of the drop down do a submit:
<select name='myfield' onchange='this.form.submit()'>
<option .... >
...
</select>
</form>
That way, when the user changes the value on the dropdown, the form will be submited as if the user clicked on submit. Python code on the server will run. The browser will load the answer.
Another popular way would be to use javascript's XmlHTTPRequest DOM API to send the request. That way you can receive the value in python and send an answer, which in turn will be received by the javascript code in the browser. That code can change parts of the page based on the answer, without changing the entire page. This technique is called AJAX.
If you plan to write lots of javascript code, I strongly suggest using a javascript library at least to ease the pain of dealing with many browser versions. jQuery is my library of choice.
In other words, code written in javascript running in the browser talks to the code written in python running in the server.