Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 14th, 2005, 08:15 PM
lli@sos.state.tx.us
Guest
 
Posts: n/a
Default how to get select label?

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

  #2  
Old December 14th, 2005, 08:35 PM
Lawrence Oluyede
Guest
 
Posts: n/a
Default Re: how to get select label?

Il 2005-12-14, lli@sos.state.tx.us <lli@sos.state.tx.us> ha scritto:[color=blue]
> 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>'[/color]

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

--
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
  #3  
Old December 14th, 2005, 08:45 PM
lli@sos.state.tx.us
Guest
 
Posts: n/a
Default Re: how to get select label?

Sorry , I forget to say that. I use CGI, HTML and python.

LLI

  #4  
Old December 14th, 2005, 09:45 PM
Lawrence Oluyede
Guest
 
Posts: n/a
Default Re: how to get select label?

Il 2005-12-14, lli@sos.state.tx.us <lli@sos.state.tx.us> ha scritto:[color=blue]
> Sorry , I forget to say that. I use CGI, HTML and python.[/color]

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

ps. do you really need CGIs ?


--
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
  #5  
Old December 14th, 2005, 10:05 PM
lli@sos.state.tx.us
Guest
 
Posts: n/a
Default Re: how to get select label?

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

  #6  
Old December 14th, 2005, 10:15 PM
Lawrence Oluyede
Guest
 
Posts: n/a
Default Re: how to get select label?

Il 2005-12-14, lli@sos.state.tx.us <lli@sos.state.tx.us> ha scritto:[color=blue]
> 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'.[/color]

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.


--
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"
  #7  
Old December 14th, 2005, 10:35 PM
Yuri
Guest
 
Posts: n/a
Default Re: how to get select label?

lli@sos.state.tx.us wrote:[color=blue]
> 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.[/color]

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>
  #8  
Old December 15th, 2005, 12:05 AM
Dan M
Guest
 
Posts: n/a
Default Re: how to get select label?

On Wed, 14 Dec 2005 13:56:24 -0800, lli wrote:
[color=blue]
> 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[/color]

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.
  #9  
Old December 15th, 2005, 03:15 AM
Mike Meyer
Guest
 
Posts: n/a
Default Re: how to get select label?

Dan M <dan@wolf.com> writes:[color=blue]
> On Wed, 14 Dec 2005 13:56:24 -0800, lli wrote:[color=green]
>> 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'.[/color]
> 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.[/color]

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

<mike
--
Mike Meyer <mwm@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles