how to get select label?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lli@sos.state.tx.us

    #1

    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

  • Lawrence Oluyede

    #2
    Re: how to get select label?

    Il 2005-12-14, lli@sos.state.t x.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"

    Comment

    • lli@sos.state.tx.us

      #3
      Re: how to get select label?

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

      LLI

      Comment

      • Lawrence Oluyede

        #4
        Re: how to get select label?

        Il 2005-12-14, lli@sos.state.t x.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"

        Comment

        • lli@sos.state.tx.us

          #5
          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

          Comment

          • Lawrence Oluyede

            #6
            Re: how to get select label?

            Il 2005-12-14, lli@sos.state.t x.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"

            Comment

            • Yuri

              #7
              Re: how to get select label?

              lli@sos.state.t x.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>

              Comment

              • Dan M

                #8
                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.

                Comment

                • Mike Meyer

                  #9
                  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.or g> http://www.mired.org/home/mwm/
                  Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

                  Comment

                  Working...