how to get select label?

L

lli

Hi Guys,

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.


Any help is appricated.


LLI
 
L

Lawrence Oluyede

Il 2005-12-14 said:
Hi Guys,

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>'

Which web technology/framework are you using that requires plains print
an this odd HTML? CGI?
 
L

Lawrence Oluyede

Il 2005-12-14 said:
Sorry , I forget to say that. I use CGI, HTML and python.

Why you need to get the text value, don't you have it when you
create the page?

ps. do you really need CGIs ?
 
L

lli

I build web application. So I use CGI. I need to show select text in
the html page. Now I can only display select value such as '001'. But I
need to display its text 'AAA'.

LLI
 
L

Lawrence Oluyede

Il 2005-12-14 said:
I build web application. So I use CGI. I need to show select text in
the html page. Now I can only display select value such as '001'. But I
need to display its text 'AAA'.

There are tons of way to build web apps in Python and CGI is the last I
rely on. Anyway you can make a dirty trick passing in hidden HTML fields
the text values and match against.
 
Y

Yuri

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>
 
D

Dan M

I build web application. So I use CGI. I need to show select text in
the html page. Now I can only display select value such as '001'. But I
need to display its text 'AAA'.

LLI

I'm a Python newbie, so by all means verify this answer with more
experienced folks. But what you're running into is a limitation of
HTML/HTTP/CGI. When your form contains a <SELECT> element, the values that
get passed to the CGI are the VALUE elements. If you want to get, for
example, AAA then you would need to put AAA in the VALUE field.
 
M

Mike Meyer

Dan M said:
I'm a Python newbie, so by all means verify this answer with more
experienced folks. But what you're running into is a limitation of
HTML/HTTP/CGI. When your form contains a <SELECT> element, the values that
get passed to the CGI are the VALUE elements. If you want to get, for
example, AAA then you would need to put AAA in the VALUE field.

If you leave the VALUE attribute, you'll get the contents of the
OPTION element. This saves having to duplicate the value.

<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,246
Latest member
softprodigy

Latest Threads

Top