Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question pulling face value from list options

    Mind my ingorance...
    I have a drop down list which is similar to as follows:

    <Input......>
    <option Value="001">Red</Option>
    <option Value="002">Blue</Option>
    <option Value="003">Green</Option>
    <option Value="004">Purple</Option>
    ....

    on posting the form, i only want to grab the face (name of the color) value... not the actual value to the selected option, then using what ever call i should use... GetParam("???") or what ever

    thanx

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Then use the value as the color name:

    <option value="red">red</option>



    Either that, or use some logic to change 001 to red later on, etc.:

    If Request.Form("mycolor") = "001" Then mycolor = "red"

    That's not the most elegant way to do it, but it works. You could also make arrays, etc...
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the best way to handle this of course depends on how you create the drop down, and what you want to do with the value.

    whammy's sollution is fine for a non-databasedriven app, buth it might be more efficient to generate the dropdown, based on the colors in your DB. (remember thet html was ment to be generated automatically !)

    after the form was posted, you could translate the value back into the colours name.

    it takes a little bit longer, buth its it doesn't give you any 'updating problems'.



    example code to generate drop down list (some of it is in dutch, buth that shouln't be a problem, I think)

    <form action="ven_eigenschappen_soort.asp" target="body" id="FORM1" method="post" name="FORM1">
    <b>Klik op de gewenste soort.</b>
    <p><select id="select1" name="soorten" size="10" onclick="submit();">
    <%
    dim conGranIT
    set conGranIT=server.CreateObjec ("adodb.connection
    conGranIT.Open("provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("granit.mdb"))
    dim rsSoort 'variabele voor recordset declareren
    set rsSoort = server.CreateObject("adodb.recordset") dim
    sql="select nummer,naam from soorten where categorie=eencategorie"
    sql=replace(sql,"eencategorie",request.form("categorie"))
    rsSoort.Open sql, conGranIT


    do while rsSoort.EOF=false
    Response.Write("<option value=" & rsSoort.Fields("nummer")& ">")
    Response.Write(server.HTMLEncode(rsSoort.Fields("naam")) & "</option>")
    rsSoort.MoveNext
    loop



    rsSoort.Close
    conGranIT.Close

    set rsSoort=nothing
    set conGranIT = nothing

    %>

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    IMHO you should do this on the client side before passing the value. In general, if the client side is where you are selecting/building/prompting for/etc. values then that's where you should tweak things so that the exact value you want is passed - NOT tweaking the value after you pass it. Don't force your server-side to have to "know" things it shouldn't have to.

    Besides all that above; the DOM gives you some very handy properties with which to manipulate the <select> object - and you loose all that in the request.form collection.

    Here's how it might be done - in Javascript on the client:

    NOTE:
    form = the name of your HTML form
    color = the name of your select object

    Code:
    for (var i=0; i<form.color.length; i++) {
       if (form.color.options[i].selected)
          form.color.options[i].value = form.color.options[i].text;
    }
    There! You might put this in a function called by an "onchange" event in your <select> object.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just ran into this in HTML 4 Unleashed
    The OPTION element can also have a specified value assigned to it, but that's not required. If it's absent, the contents of the OPTION element will become the “value” part of the name/value pair
    In other words leave off the "value='004'" part and the text part becomes the value passed in the form submission.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Pretty much the same thing I said, just make the values the same as the text and validate them later.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    New Coder
    Join Date
    Aug 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In the end i used the following...
    Client side manipulation... so prolly wasn't the best posting it in the Server side forums... but thanx anyway


    <form>
    <select name="tst">
    <option Value="001">Red</Option>
    <option Value="002">Blue</Option>
    <option Value="003">Green</Option>
    <option Value="004">Purple</Option>
    </select>
    <input type="button" value="test" onClick="alert(this.form.tst[this.form.tst.selectedIndex].text);">
    </form>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •