简体   繁体   中英

How to request for select tag name choice, not a value choice in flask?

Let's say you have the following form in HTML:

<form method="POST">        
    <select class="form-control" id="startyear" name="startyear">
        <option value="2005">first</option>
        <option value="2006">second</option>
        <option value="2007">third</option></select>
</form>

I know that in order to access the value of select field in flask one needs to request:

len = request.form.get(startyear)

This way however, we obtain values, so "2005", "2006" etc. Is there a way to obtain names of those values instead? So "first", "second" etc.? Thank you

You can find details here select developer.Mozilla

Each option element should have a value attribute containing the data value to submit to the server when that option is selected; if no value attribute is included, the value defaults to the text contained inside the element

So get the text: don't set the value, if you set the value you'll get it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM