How can I get the dropdown's selected value

Discussion in 'ASP General' started by London, Oct 2, 2003.

  1. London

    London Guest

    Hello
    Can you help me.
    By ASP
    How can I get the dropdown(control'name)'s selected value?
    What is it's property'name?
    London, Oct 2, 2003
    #1
    1. Advertising

  2. London

    Bob Barrows Guest

    London wrote:
    > Hello
    > Can you help me.
    > By ASP
    > How can I get the dropdown(control'name)'s selected value?
    > What is it's property'name?


    Give the dropdown element a name, using its name property.

    Then, in the asp page to which you are submitting the form, just do this (if
    using POST):
    <%
    selectedvalue = request.form("name_of_dropdown")
    .....
    %>

    or this, if using GET:
    <%
    selectedvalue = request.querystring("name_of_dropdown")
    .....
    %>

    HTH,
    Bob Barrows
    Bob Barrows, Oct 2, 2003
    #2
    1. Advertising

  3. London

    Randy Rahbar Guest

    > By ASP
    > How can I get the dropdown(control'name)'s selected value?
    > What is it's property'name?


    Using ASP, you'll have to resubmit your form first. After submitting your
    form, try the following...

    'Let's assume the name of your dropdown list is ControlName.
    Response.Write request("ControlName")
    Randy Rahbar, Oct 2, 2003
    #3
  4. London

    Ray at Guest

    <select name="XYZ">
    <option value="1">One</option>
    <option value="2">Two</option>
    </select>

    If method="post" -
    Request.Form("XYZ")

    If method="get"
    Request.Querystring("XYZ")

    Ray at work
    "London" <> wrote in message
    news:...
    > Hello
    > Can you help me.
    > By ASP
    > How can I get the dropdown(control'name)'s selected value?
    > What is it's property'name?
    >
    Ray at, Oct 2, 2003
    #4
  5. First it has to be in a Form and the Form has to be "Submitted" to an
    ASP page. If the control's Name is "DdList", then the ASP page you
    submitted to would retreive it with any one of these:

    Request.Form("DdList")

    How you handle it from that point is up to you.


    --

    Phillip Windell [CCNA, MVP, MCP]

    WAND-TV (ABC Affiliate)
    www.wandtv.com

    "London" <> wrote in message
    news:...
    > Hello
    > Can you help me.
    > By ASP
    > How can I get the dropdown(control'name)'s selected value?
    > What is it's property'name?
    >
    Phillip Windell, Oct 2, 2003
    #5
  6. In article <>, louxiangyu2000
    @yahoo.co.jp says...
    > Hello
    > Can you help me.
    > By ASP
    > How can I get the dropdown(control'name)'s selected value?
    > What is it's property'name?
    >
    >

    Man, you *are* an idoit!

    -- Guinness
    Guinness Mann, Oct 2, 2003
    #6
  7. London

    Ray at Guest

    Don't listen to him, London. Everyone posting here started out as an egg
    and a sperm and had to take it from there. You can post any questions here,
    from total beginner level, to total expert level. Don't be discouraged by
    the idoits [sic] who post nonsense.

    Ray at work


    "Guinness Mann" <> wrote in message
    news:...
    > In article <>, louxiangyu2000
    > @yahoo.co.jp says...
    > > Hello
    > > Can you help me.
    > > By ASP
    > > How can I get the dropdown(control'name)'s selected value?
    > > What is it's property'name?
    > >
    > >

    > Man, you *are* an idoit!
    >
    > -- Guinness
    Ray at, Oct 2, 2003
    #7
  8. In article <#>, "Ray at <%
    =sLocation%>" <myfirstname at lane34 dot com> says...
    > Don't be discouraged by the idoits [sic] who post nonsense.
    > > > Can you help me.
    > > > By ASP
    > > > How can I get the dropdown(control'name)'s selected value?
    > > > What is it's property'name?
    > > >
    > > >

    > > Man, you *are* an idoit!


    I just wanted to use the word idoit!
    Guinness Mann, Oct 2, 2003
    #8
  9. In article <#>, "Ray at <%
    =sLocation%>" <myfirstname at lane34 dot com> says...
    > Don't listen to him, London. Everyone posting here started out as an egg
    > and a sperm and had to take it from there. You can post any questions here,
    > from total beginner level, to total expert level. Don't be discouraged by
    > the idoits [sic] who post nonsense.
    >
    > Ray at work


    P.S. I notice you didn't answer his question... :)
    Guinness Mann, Oct 2, 2003
    #9
  10. London

    Ray at Guest

    Ah, but I did.

    "Guinness Mann" <> wrote in message
    news:...
    >
    > P.S. I notice you didn't answer his question... :)
    Ray at, Oct 3, 2003
    #10
  11. Actually you can just:
    Request("XYZ")

    It will look for querystring first then post if no
    querystring is present. I use this ocassionally because
    sometimes you need a user to post info to a page and I
    may also have a direct link from another page with posted
    info in the querystring as a shortcut.


    >-----Original Message-----
    ><select name="XYZ">
    > <option value="1">One</option>
    > <option value="2">Two</option>
    ></select>
    >
    >If method="post" -
    > Request.Form("XYZ")
    >
    >If method="get"
    > Request.Querystring("XYZ")
    >
    >Ray at work
    >"London" <> wrote in message
    >news:...
    >> Hello
    >> Can you help me.
    >> By ASP
    >> How can I get the dropdown(control'name)'s selected

    value?
    >> What is it's property'name?
    >>

    >
    >
    >.
    >
    Michael Ralph, Oct 3, 2003
    #11
  12. London

    Ray at Guest

    That's totally inefficient and bound to cause bugs. You should always
    explicitly state which collection you want to look in. All shortcuts waste
    future time.

    Ray at home

    "Michael Ralph" <> wrote in message
    news:10e501c3899d$d9ca4b10$...
    > Actually you can just:
    > Request("XYZ")
    >
    > It will look for querystring first then post if no
    > querystring is present. I use this ocassionally because
    > sometimes you need a user to post info to a page and I
    > may also have a direct link from another page with posted
    > info in the querystring as a shortcut.
    >
    >
    Ray at, Oct 3, 2003
    #12
  13. London

    Bob Barrows Guest

    Michael Ralph wrote:
    > Actually you can just:
    > Request("XYZ")
    >
    > It will look for querystring first then post if no
    > querystring is present. I use this ocassionally because
    > sometimes you need a user to post info to a page and I
    > may also have a direct link from another page with posted
    > info in the querystring as a shortcut.
    >

    This is not recommended. In addition to slowing down your code (due to
    forcing all the Request collections to be searched, not just the Form and
    Querystring collections), it can cause unintended results:
    If you happen to use a control name in your form that is the same as the
    name of a variable in the servervariables collection (such as "URL"), you
    will get the servervariable value, not the form or querystring value.

    It is better to do something like this:

    sVar = Request.Form("XYZ")
    if len(sVar) = 0 then sVar = Request.Querystring("XYZ")

    Bob Barrows
    Bob Barrows, Oct 3, 2003
    #13
  14. London

    London Guest

    Thank you very much.
    but
    I wrote this code:

    dim xy
    Response.Write "<FORM>"
    Response.Write "<B><TR><SELECT name=""select1"" Width=394px>"
    Response.Write "<OPTION value=""1"">One</OPTION>"
    Response.Write "<OPTION value=""2"">Two</OPTION>"
    Response.Write "</SELECT></TR></B>"
    Response.Write "</FORM>" & Chr(13)
    xy=Request.Querystring("select1")
    Response.Write "<P><input type=""text"" id=""text1"" name=""text1""></P>"
    Response.Write "<P><input type=""button"" value=""ButtonX""
    onclick=""text1.value='" & xy & "';"" METHOD=""get"" id=button1
    name=button1></P>"

    I click the button(ButtonX),but the testbox(text1) is none.
    Can you more help me
    London, Oct 6, 2003
    #14
  15. London

    Bob Barrows Guest

    London wrote:
    > Thank you very much.
    > but
    > I wrote this code:
    >
    > dim xy
    > Response.Write "<FORM>"
    > Response.Write "<B><TR><SELECT name=""select1"" Width=394px>"
    > Response.Write "<OPTION value=""1"">One</OPTION>"
    > Response.Write "<OPTION value=""2"">Two</OPTION>"
    > Response.Write "</SELECT></TR></B>"
    > Response.Write "</FORM>" & Chr(13)
    > xy=Request.Querystring("select1")
    > Response.Write "<P><input type=""text"" id=""text1""
    > name=""text1""></P>" Response.Write "<P><input type=""button""
    > value=""ButtonX"" onclick=""text1.value='" & xy & "';""
    > METHOD=""get"" id=button1 name=button1></P>"
    >
    > I click the button(ButtonX),but the testbox(text1) is none.
    > Can you more help me


    You're doing too much response.write'ing. This is very hard to follow (and,
    it must be hard to write). Nevertheless, some problems do reveal themselves:

    1. METHOD is an attribute of a FORM element, not an INPUT element
    2. You aren't telling the form where it should be submitted - use the FORM
    element's ACTION attribute
    3. You aren't submitting the form - you need to
    a. have a Submit input element within the FORM, or
    b. have your button input element's onclick event include code to submit
    the form
    4. You do not seem to understand when the xy variable will be populated.
    When an asp page is called on the server, all server-side code is executed
    before the resulting html is sent to the client. So, in your code, when the
    asp page is called, the hetml that is sent to the client browser includes
    this code (which you can verify by using View Source in your browser
    window):
    <input type="text" id="text1" name="text1">
    <input type="button" value="ButtonX"" onclick="text1.value='';"
    METHOD=""get"" id=button1 name=button1>

    You see? When this button is clicked, it will set the text1.value to a blank
    string. And nothing else will happen.

    But let's suppose that you also included code to submit the form. Assuming
    you've set the ACTION attribute to submit the form to itself, when you submi
    t the page after select "Two" in the dropdown, and it reloads in the client
    browser, the html source of the reloaded page will look like this:
    <input type="text" id="text1" name="text1">
    <input type="button" value="ButtonX"" onclick="text1.value='2';"
    METHOD=""get"" id=button1 name=button1>

    So, the textbox will still be blank ... until you click the button. But,
    when you click the button, the form will be resubmitted, so the user will
    never have a chance to see the new value of the textbox.


    Here is what I would do (this code has been tested - give it a try):

    <%
    'This page is called ASPPage6.asp
    option explicit
    dim xy
    xy=Request.Querystring("select1")
    %>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    <FORM action="ASPPage6.asp" method=GET id=form1 name=form1>
    <SELECT id=select1 name=select1>
    <OPTION value="1">One</OPTION>
    <OPTION value="2">Two</OPTION>
    </SELECT>
    <INPUT type="submit" value="Submit" id=submit1 name=submit1>
    <P>
    <INPUT type="text" id=text1 name=text1 value="<%=xy%>">
    </P>
    </FORM>
    </BODY>
    </HTML>

    When the page initially loads in the browser, the textbox will be blank.
    When you select an option from the dropdown and click the Submit button, the
    page will reload and the textbox will contain the selected value

    HTH,
    Bob Barrows
    Bob Barrows, Oct 6, 2003
    #15
  16. London

    London Guest

    Thank you very much.
    but
    I wrote this code:

    <%@ Language=VBScript %>
    <%
    option explicit
    dim xy
    xy=Request.Querystring("select1")
    %>
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Content-Type" Content="text/html; charset=x-sjis">
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    </HEAD>
    <BODY>
    <FORM id=form1 name=form1 action=ASPPage6.asp method=get>
    <SELECT id=select1 name=select1>
    <OPTION value=1 selected>One</OPTION>
    <OPTION value=2>Two</OPTION>
    </SELECT>
    <P><INPUT id=submit1 type=submit value=Submit name=submit1></P>
    <P><INPUT id=text1 value="<%=xy%>" name=text1></P>
    </FORM>
    </BODY>
    </HTML>

    When I click the submit button,the page is error.Error message:
    "
    Page not found
    ....
    HTTP 404 - Files not found
    Internet Information Services
    ....
    "
    Can you more help me
    London, Oct 7, 2003
    #16
  17. London

    Bob Barrows Guest

    Ummmm - replace "ASPPage6.asp" with the actual name of the asp page???

    By the war, I very deliberately surrounded the attribute values (such as
    "ASPPage6.asp") with quotes in the example I provided. I do not see quotes
    in your new code here.

    Bob Barrows

    ondon wrote:
    > Thank you very much.
    > but
    > I wrote this code:
    >
    > <%@ Language=VBScript %>
    > <%
    > option explicit
    > dim xy
    > xy=Request.Querystring("select1")
    > %>
    > <HTML>
    > <HEAD>
    > <META HTTP-EQUIV="Content-Type" Content="text/html; charset=x-sjis">
    > <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    > </HEAD>
    > <BODY>
    > <FORM id=form1 name=form1 action=ASPPage6.asp method=get>
    > <SELECT id=select1 name=select1>
    > <OPTION value=1 selected>One</OPTION>
    > <OPTION value=2>Two</OPTION>
    > </SELECT>
    > <P><INPUT id=submit1 type=submit value=Submit name=submit1></P>
    > <P><INPUT id=text1 value="<%=xy%>" name=text1></P>
    > </FORM>
    > </BODY>
    > </HTML>
    >
    > When I click the submit button,the page is error.Error message:
    > "
    > Page not found
    > ...
    > HTTP 404 - Files not found
    > Internet Information Services
    > ...
    > "
    > Can you more help me
    Bob Barrows, Oct 7, 2003
    #17
  18. London

    SW Guest

    I have a similar task to "London's" and am having trouble finding the
    easiest way to do it. I do have some asp experience but sometimes you
    have to do new things...

    I have built a form and have it submitting to the server fine. The
    problem I am having is that in many text boxes I need to be able to go
    "lookup" the value the user typed in and then populate another text
    box with an answer (from another table).

    Example:
    The user is typing in a mechanical problem description. One field is
    a "Part number" - when the user types that in and moves off that field
    I have to go to another table with that part number and lookup the
    "Description" of that part number, I then have to auto-fill that text
    box on the screen. I can do it with a Submit button but the customer
    wants this to happen automatically (!darn customers!) without having
    to click on anything.

    I have to use all VBScript because of customer requirements so I don't
    think the OnBlur() attribute is available to me.

    I thought I could put some VBScript lookup code in the 'value'
    attribute of the "part number" field?? But I can't find any
    examples of people doing this on any of these groups.

    Anyone have some ideas or know where some examples of this might be?

    Thanks for the help!

    Susan Williamson
    SW, Oct 9, 2003
    #18
  19. In article <>,
    says...
    > The user is typing in a mechanical problem description. One field is
    > a "Part number" - when the user types that in and moves off that field
    > I have to go to another table with that part number and lookup the
    > "Description" of that part number, I then have to auto-fill that text
    > box on the screen. I can do it with a Submit button but the customer
    > wants this to happen automatically (!darn customers!) without having
    > to click on anything.


    Susan, I don't understand your problem well enough to answer your
    question, but I do have a couple of comments.

    First, this problem would be trivial in .NET. Perhaps that's not an
    option for you.

    Secondly, another group here at work has a sort of related situation.
    What they do is bring an entire table of data over to the client along
    with the form. Then as the user moves around on the form they use
    javascript to update various fields. Note that our application runs on
    an intranet, and we have complete control over browsers and settings.

    -- Rick
    Guinness Mann, Oct 9, 2003
    #19
  20. London

    janice li Guest

    I need help to display the selected value from database in the dropdown
    list. Following is my code...but there are some error:

    while NOT rs.EOF
    Response.Write ("<option value = '" & rs("Description") & "'")
    Response.Write (">")
    If rs("Description") = rsStatus("sc_status") Then
    Response.Write ("<Option value = '" & rsStatus("sc_status") & "'
    SELECTED>")
    Else
    Response.Write (rs("Description"))
    Response.Write ("</option>")
    rsStatus.MoveNext
    end if
    wend

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    janice li, Sep 1, 2004
    #20
    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. Andy Sutorius

    Get selected value of dropdown from panel

    Andy Sutorius, Feb 23, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    373
    Malik Asif Joyia
    Feb 24, 2005
  2. Andy Sutorius

    Get selected value of dropdown from panel

    Andy Sutorius, Feb 23, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    537
    =?Utf-8?B?RG90TmV0SmVyb21l?=
    Feb 24, 2005
  3. Andy Sutorius

    Get selected value of dropdown from panel

    Andy Sutorius, Feb 24, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    324
    Andy Sutorius
    Feb 24, 2005
  4. Andy Sutorius

    how to get selected value from dropdown list

    Andy Sutorius, Mar 15, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    82,175
    raouf2me
    Oct 29, 2012
  5. vishnu
    Replies:
    1
    Views:
    1,182
    Patrick.O.Ige
    Mar 25, 2006
Loading...

Share This Page