how to get select label?

Yuri nospamplease at nada.com
Wed Dec 14 23:24:28 CET 2005


lli at sos.state.tx.us wrote:
> I built a select in a form. My select is:
>             print '<SELECT NAME="county">'
>             print '<OPTION VALUE="000">ALL'
>             print '<OPTION VALUE="001">AAA'
>             print '<OPTION VALUE="002">BBB'
>             print '</SELECT>'
> 
> I can get which item value users select. For example users select item
> 2, I can get its value "001". But now I want to get item label "AAA",
> not its value "001". How I can do this. I use python to code.

This is actually a HTML question, not python:

You're doing it almost right except that the option tag should be closed 
as always.

<SELECT NAME="county">
   <OPTION VALUE="000">ALL</OPTION>
   <OPTION VALUE="001">AAA</OPTION>
   <OPTION VALUE="002">BBB</OPTION>
</SELECT>

better yet but may not be supported in all browsers (try):

<SELECT NAME="county">
   <OPTION VALUE="000" LABEL="ALL"></OPTION>
   <OPTION VALUE="001" LABEL="AAA"></OPTION>
   <OPTION VALUE="002" LABEL="BBB"></OPTION>
</SELECT>



More information about the Python-list mailing list