How do I select item in <SELECT>

Discussion in 'ASP General' started by K. Lobe, Jul 2, 2003.

  1. K. Lobe

    K. Lobe Guest

    list box based on a POST method to the same page.

    frm.cmbList.Value=Request.Form("cmbList") doesn't work.

    When the page loads, it reloads the <SELECT>, so not sure how to get the
    list to go to the item.

    Any ideas?

    many thnx,
    Kevin
    K. Lobe, Jul 2, 2003
    #1
    1. Advertising

  2. K. Lobe

    Bob Barrows Guest

    K. Lobe wrote:
    > list box based on a POST method to the same page.
    >
    > frm.cmbList.Value=Request.Form("cmbList") doesn't work.
    >
    > When the page loads, it reloads the <SELECT>, so not sure how to get
    > the list to go to the item.
    >
    > Any ideas?
    >

    Assuming you've got a window_onload event:
    frm.cmbList.Value="<%=Request.Form("cmbList")%>"
    Bob Barrows
    Bob Barrows, Jul 2, 2003
    #2
    1. Advertising

  3. At the end of the page... you want to make sure this doesn't execute until
    after the <select> has loaded.

    Something like this... see a JavaScript newsgroup for better syntax and
    examples (the only ASP-related part here is getting the ASP variable into
    client-side script).

    <script>
    var selected = 0;
    for (i=0; i<document.frm.cmbList.options.length; i++)
    {
    if (document.frm.cmbList.options.value ==
    "<%=request.form("cmbList")%>")
    {
    selected = i;
    i = document.frm.cmbList.options.length;
    }
    }
    document.frm.cmbList.selectedIndex = selected;
    </script>

    You could also consider building the select list in ASP, e.g.

    <%
    dim options(3)
    options(0) = "foo"
    options(1) = "bar"
    options(2) = "fu"
    options(3) = "barred"
    response.write "<select>"
    for i = 0 to 3
    response.write "<option value='" & options(i) & "'"
    if options(i) = request.form("cmbList") then
    response.write " selected"
    end if
    response.write ">" & options(i)
    next
    response.write "</select>"
    %>



    "K. Lobe" <> wrote in message
    news:...
    > list box based on a POST method to the same page.
    >
    > frm.cmbList.Value=Request.Form("cmbList") doesn't work.
    >
    > When the page loads, it reloads the <SELECT>, so not sure how to get the
    > list to go to the item.
    >
    > Any ideas?
    >
    > many thnx,
    > Kevin
    >
    >
    Aaron Bertrand - MVP, Jul 2, 2003
    #3
  4. K. Lobe

    K. Lobe Guest

    Worked! Thanks.


    "Bob Barrows" <> wrote in message
    news:ubw$...
    > K. Lobe wrote:
    > > list box based on a POST method to the same page.
    > >
    > > frm.cmbList.Value=Request.Form("cmbList") doesn't work.
    > >
    > > When the page loads, it reloads the <SELECT>, so not sure how to get
    > > the list to go to the item.
    > >
    > > Any ideas?
    > >

    > Assuming you've got a window_onload event:
    > frm.cmbList.Value="<%=Request.Form("cmbList")%>"
    > Bob Barrows
    >
    >
    K. Lobe, Jul 2, 2003
    #4
    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. ssoss

    Display Related Item or Add Item

    ssoss, Sep 17, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    481
    ssoss
    Sep 19, 2003
  2. Replies:
    2
    Views:
    604
  3. root

    item[LENGTH] vs. *item and malloc()

    root, Aug 21, 2003, in forum: C Programming
    Replies:
    2
    Views:
    381
    Eric Sosman
    Aug 21, 2003
  4. Steven Bethard
    Replies:
    0
    Views:
    383
    Steven Bethard
    Mar 12, 2005
  5. Replies:
    2
    Views:
    179
Loading...

Share This Page