Getting option's text value

Discussion in 'ASP General' started by Raul, Apr 10, 2007.

  1. Raul

    Raul Guest

    Hi,

    I have a select list that gets populated from the DB. When the user
    makes a selection I am able to retrieve this value via
    Request.Form(...)

    However, I am wondering if you can retrieve the text value using ASP??
    I know this can be done in JavaScript using the options text
    attribute, but it is possible in ASP?

    Any input would be appreciated....Thanks!
     
    Raul, Apr 10, 2007
    #1
    1. Advertising

  2. Raul wote:
    > Hi,
    >
    > I have a select list that gets populated from the DB. When the user
    > makes a selection I am able to retrieve this value via
    > Request.Form(...)
    >
    > However, I am wondering if you can retrieve the text value using ASP??
    > I know this can be done in JavaScript using the options text
    > attribute, but it is possible in ASP?
    >
    > Any input would be appreciated....Thanks!


    You could append the value to the option value, eg: <option value="<
    %=rsarr(0,i)%>:<%=rsarr(1,i)%>"><%=rsarr(1,i)%></option>

    Then when you get the values
    things = split(request.form("that"),":")
    optionvalue = things(0)
    textvalue = things(1)

    --
    Adrienne Boswell at work
    Administrator nextBlock.com
    http://atlas.nextblock.com/files/
    Please respond to the group so others can share
     
    Adrienne Boswell, Apr 10, 2007
    #2
    1. Advertising

  3. Raul

    Guest

    On 10 Apr, 13:13, "Raul" <> wrote:
    > Hi,
    >
    > I have a select list that gets populated from the DB. When the user
    > makes a selection I am able to retrieve this value via
    > Request.Form(...)
    >
    > However, I am wondering if you can retrieve the text value using ASP??
    > I know this can be done in JavaScript using the options text
    > attribute, but it is possible in ASP?
    >
    > Any input would be appreciated....Thanks!


    select.asp
    <body>
    <form name = form1 method = post action = "PrintSelectList.asp">
    <select name = "cboToppings" size = 4 multiple>
    <option selected>Cheese
    <option selected>Totmato Sauce
    <option>Olive Oil
    <option>Barbecue Sauce
    <option>Pepperoni
    <option>Sausage
    <option>Mushrooms
    <option>Onions
    <option>Ham
    <option>Pineapple
    <option>Green Peppers
    <option>Anchovies
    </select>
    <p>
    <input type = submit name = cmdSubmit value = "Deliver It">
    </p>
    </form>
    </body>


    PrintSelectList.asp
    <body>
    <%
    dim strSelect
    dim i
    strSelect = split(Request.Form("cboToppings"), ", ")
    length = len(str)
    for i = 0 to UBound(strSelect)
    response.write strSelect(i) & " "
    next
    %>
    </body>
     
    , Apr 11, 2007
    #3
  4. Raul

    Raul Guest

    On Apr 11, 2:00 am, wrote:
    > select.asp
    > <body>
    > <form name = form1 method = post action = "PrintSelectList.asp">
    > <select name = "cboToppings" size = 4 multiple>
    > <option selected>Cheese
    > <option selected>Totmato Sauce
    > <option>Olive Oil
    > <option>Barbecue Sauce
    > <option>Pepperoni
    > <option>Sausage
    > <option>Mushrooms
    > <option>Onions
    > <option>Ham
    > <option>Pineapple
    > <option>Green Peppers
    > <option>Anchovies
    > </select>
    > <p>
    > <input type = submit name = cmdSubmit value = "Deliver It">
    > </p>
    > </form>
    > </body>
    >
    > PrintSelectList.asp
    > <body>
    > <%
    > dim strSelect
    > dim i
    > strSelect = split(Request.Form("cboToppings"), ", ")
    > length = len(str)
    > for i = 0 to UBound(strSelect)
    > response.write strSelect(i) & " "
    > next
    > %>
    > </body>


    Thanks for the input everyone. In the meantime I thought of a
    solution that nobody else posted on here...I personally like it more.
    Add an onclick event to the option element. Whenever it gets clicked,
    save the text into a hidden form field. This value can then be used
    as you like (I needed it to save the user input to the DB)

    Cheers!
     
    Raul, Apr 13, 2007
    #4
  5. Raul wrote:
    > Thanks for the input everyone. In the meantime I thought of a
    > solution that nobody else posted on here...I personally like it more.
    > Add an onclick event to the option element. Whenever it gets clicked,
    > save the text into a hidden form field. This value can then be used
    > as you like (I needed it to save the user input to the DB)
    >

    Sure, that's one of the ways to do this, but why do you like it better?
    Now you're at the mercy of a user who can easily disable javascript in
    his browser.
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Apr 13, 2007
    #5
  6. Raul

    Raul Guest

    On Apr 13, 2:00 pm, "Bob Barrows [MVP]" <>
    wrote:
    > Sure, that's one of the ways to do this, but why do you like it better?
    > Now you're at the mercy of a user who can easily disable javascript in
    > his browser.


    Good point on that one, but I know all our users dont have JavaScript
    disabled (its not a public site). If they had JavaScript disabled
    then the site will not function properly.

    To answer your question, I like it better because it seems more
    elonquent than adding a delimiter to the value and appending the
    description. Its just my opinion obviously, it is largely a stylistic
    choice. Does anyone agree or am I on my own on this one?
     
    Raul, Apr 13, 2007
    #6
  7. Raul wrote:
    > Thanks for the input everyone. In the meantime I thought of a
    > solution that nobody else posted on here...I personally like it
    > more. Add an onclick event to the option element. Whenever it
    > gets clicked, save the text into a hidden form field. This
    > value can then be used as you like (I needed it to save the
    > user input to the DB)


    I fail to see how that is an improvement over getting the value from the
    database. The advantage of direct DB query is especially acute if the table
    you are updating is in the same database as the one you are filling options
    from, since you can simply do it in the DB at insert.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Apr 13, 2007
    #7
  8. Raul wrote:
    > Good point on that one, but I know all our users dont have
    > JavaScript disabled (its not a public site). If they had
    > JavaScript disabled then the site will not function properly.


    You are making far too many assumptions. I, for one, run the NoScript
    extension when I browse the web. With it, I can temporarily turn on
    scripting for a site, get past the non-working stuff, and turn it back off.
    How exactly do you think you could circumvent that?

    I don't even know where to begin with the Web Developer extension. There is
    almost nothing you can do client-side to prevent me from controlling the
    content of my requests. You should, therefore, concentrate on handling
    requests, not dictating them.


    > To answer your question, I like it better because it seems more
    > elonquent than adding a delimiter to the value and appending
    > the description.


    In the sense that it more explicitly divides the text and value, I agree
    that this is a better approach than delimited concatenation. But neither is
    robust.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Apr 13, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Julien ROUZIERES

    g++ -pg option and -shared option

    Julien ROUZIERES, Dec 21, 2004, in forum: C++
    Replies:
    1
    Views:
    774
    GianGuz
    Dec 21, 2004
  2. Cas
    Replies:
    5
    Views:
    817
    Kevin Jones
    Aug 28, 2006
  3. Kevin Blount

    page.aspx?option - how to detect "option"

    Kevin Blount, Nov 28, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    629
    =?Utf-8?B?RWVyYWo=?=
    Nov 28, 2006
  4. Lucas Malor
    Replies:
    2
    Views:
    348
    Mel Wilson
    Apr 6, 2007
  5. Lucas Malor
    Replies:
    4
    Views:
    295
    Bruno Desthuilliers
    Apr 11, 2007
Loading...

Share This Page