<select> how to get id of selected item?

Posted on 2011-10-11
Last Modified: 2012-05-12
Hello experts!

I have <select> list populated dynamically:

<select id="feat1" name="feat1" title="feat1">
@foreach (var p in featQuery)
  counter=counter + 1;
  <option id="@counter">@p.Name</option>

How can I retrieve id number of option selected by user?

To get a option I use:

value = Request.Form["feat1"];

But I do not need string, I need id here.

Thank you

Question by:panJames
    LVL 1

    Accepted Solution

    Its really very simple. Try this Jazascript code

    var x=document.getElementById("feat1").selectedIndex;

    Author Comment

    Forgot to mention: it needs to work/ cooperate with WebMatrix code.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now