DropDownList SelectedItem Javascript

Discussion in 'ASP .Net' started by Alper ÖZGÜR, Mar 6, 2006.

  1. Hi;
    I can read the selectedvalue of dropdownlist by javascript using
    this.value...
    How can i get the selectedItem.text by javascript?
    Alper ÖZGÜR, Mar 6, 2006
    #1
    1. Advertising

  2. Alper,

    this.options[this.selectedIndex].value

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Alper ÖZGÜR" <> wrote in message
    news:...
    > Hi;
    > I can read the selectedvalue of dropdownlist by javascript using
    > this.value...
    > How can i get the selectedItem.text by javascript?
    >
    >
    S. Justin Gengo [MCP], Mar 6, 2006
    #2
    1. Advertising

  3. It returns the SelectedValue... Not SelectedText.....

    "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com>, haber
    iletisinde þunlarý yazdý:...
    > Alper,
    >
    > this.options[this.selectedIndex].value
    >
    > --
    > Sincerely,
    >
    > S. Justin Gengo, MCP
    > Web Developer / Programmer
    >
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzsche
    > "Alper ÖZGÜR" <> wrote in message
    > news:...
    >> Hi;
    >> I can read the selectedvalue of dropdownlist by javascript using
    >> this.value...
    >> How can i get the selectedItem.text by javascript?
    >>
    >>

    >
    >
    Alper ÖZGÜR, Mar 6, 2006
    #3
  4. Alper,

    Sorry about that. I forgot to switch it from some of my code I copy and
    pasted. It's pretty simple really. Just switch value to text.

    this.options[this.selectedIndex].text

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Alper ÖZGÜR" <> wrote in message
    news:...
    > It returns the SelectedValue... Not SelectedText.....
    >
    > "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com>, haber
    > iletisinde þunlarý yazdý:...
    >> Alper,
    >>
    >> this.options[this.selectedIndex].value
    >>
    >> --
    >> Sincerely,
    >>
    >> S. Justin Gengo, MCP
    >> Web Developer / Programmer
    >>
    >> www.aboutfortunate.com
    >>
    >> "Out of chaos comes order."
    >> Nietzsche
    >> "Alper ÖZGÜR" <> wrote in message
    >> news:...
    >>> Hi;
    >>> I can read the selectedvalue of dropdownlist by javascript using
    >>> this.value...
    >>> How can i get the selectedItem.text by javascript?
    >>>
    >>>

    >>
    >>

    >
    >
    S. Justin Gengo [MCP], Mar 6, 2006
    #4
  5. Alper ÖZGÜR

    BigCJ29

    Joined:
    Jul 3, 2008
    Messages:
    1
    Dropdownlist and javascript...

    Hi.. I want to know a way to write a text in a textbox and find the item in a dropdownlist and put it in the top of the list? thanks...
    BigCJ29, Jul 3, 2008
    #5
  6. Alper ÖZGÜR

    arnabb4u

    Joined:
    Dec 18, 2008
    Messages:
    1
    Populate drop down as per the code written in text box

    I have just used this method in one of my .net project. u just add this method in ur .js file and call this from ur aspx page.

    function SearchItem(textbox, dropdown, chk)
    {
    if(chk)
    {
    for(var i=0; i<=dropdown.length; i++)
    {
    if(textbox.value == dropdown.value)
    {
    dropdown.selected = true;
    break;
    }
    }
    }
    else
    textbox.value = dropdown.value;
    }

    in controls page add this property in ur aspx page:
    <asp:TextBox ID="txt" runat="server" MaxLength="20" OnBlur="javascript:SearchItem(<%=txt.ClientID %>,<%=ddl.ClientID %>,true);"></asp:TextBox>
    <asp:DropDownList ID="ddl" runat="server" onchange="javascript:SearchItem(<%=txt.ClientID %>,<%=ddl.ClientID %>);" />
    :flute:
    arnabb4u, Dec 18, 2008
    #6
  7. Alper ÖZGÜR

    witnes

    Joined:
    Mar 26, 2011
    Messages:
    1
    Location:
    Ukraine, Kiev
    Html.DropDownList("selItemsPerPage1", Model.Items, new
    {
    onchange = "alert($('#selItemsPerPage1 option:selected').val());"
    }
    witnes, Mar 26, 2011
    #7
    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. Antonio D'Ottavio
    Replies:
    1
    Views:
    2,717
    Antonio D'Ottavio
    Sep 19, 2005
  2. Marina
    Replies:
    0
    Views:
    1,187
    Marina
    Jun 25, 2003
  3. Jos Branders
    Replies:
    6
    Views:
    13,053
    William F. Robertson, Jr.
    Jun 25, 2003
  4. huobazi
    Replies:
    0
    Views:
    584
    huobazi
    Jul 1, 2003
  5. Ivan
    Replies:
    4
    Views:
    8,230
Loading...

Share This Page