Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

<select> how to get id of selected item?

Posted on 2011-10-11
2
Medium Priority
?
210 Views
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>
}
</select>

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

panJames
0
Comment
Question by:panJames
2 Comments
 
LVL 1

Accepted Solution

by:
cbtahir2001 earned 2000 total points
ID: 36948835
Its really very simple. Try this Jazascript code

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

Author Comment

by:panJames
ID: 36949101
Forgot to mention: it needs to work/ cooperate with WebMatrix code.

panJames
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Over time, the online landscape has altered considerably, but that’s nothing compared to the up-and-coming trends that will shape the web design industry in the coming year. Keep reading to find out which trends will shape B2B web design in 2018.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

578 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