JavaScript: Access DropDownList's current SelectedText value?

Discussion in 'ASP .Net' started by Jeremy, Jun 27, 2004.

  1. Jeremy

    Jeremy Guest

    In client-side JavaScript, how does one retrieve into a variable the
    currently displayed text in a DropDownList control.

    I tried this, but it gets the current ID/value- not the displayed text:
    var curText = document.all("DDLSomeList").value

    This doesn't work either (although SelectedItem.Text works in code-behind):
    var curText = document.all("DDLSomeList").SelectedItem.Text;

    Thanks!
    Jeremy, Jun 27, 2004
    #1
    1. Advertising

  2. On Sun, 27 Jun 2004 14:15:15 -0700, Jeremy <> wrote:

    > In client-side JavaScript, how does one retrieve into a variable the
    > currently displayed text in a DropDownList control.
    >
    > I tried this, but it gets the current ID/value- not the displayed text:
    > var curText = document.all("DDLSomeList").value
    >
    > This doesn't work either (although SelectedItem.Text works in
    > code-behind):
    > var curText = document.all("DDLSomeList").SelectedItem.Text;
    >
    > Thanks!
    >
    >
    >

    Try

    var oDDL = document.all("DDLSomeList");
    var curText = oDDL.options[oDDL.selectedIndex].text;


    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Jun 27, 2004
    #2
    1. Advertising

  3. Jeremy

    Jeremy Guest

    Bingo!

    thanks.
    Jeremy, Jun 27, 2004
    #3
    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. Manu
    Replies:
    1
    Views:
    6,095
    Natty Gur
    Jul 20, 2003
  2. Replies:
    2
    Views:
    557
  3. Replies:
    0
    Views:
    416
  4. moonhk
    Replies:
    5
    Views:
    537
    moonhk
    Oct 11, 2006
  5. Matthew Heidemann
    Replies:
    14
    Views:
    245
    eT Ma
    Mar 22, 2011
Loading...

Share This Page