JQuery get selected text from dropdownlist?

3 $("#yourdropdownid option"). Is("selected").text() is a bit more optimized way, and $("#yourdropdownid"). Children("option").

Is("selected").text() is the fastest. – DT3 Nov 26 '11 at 20:36.

Try this: $("#myselect :selected").text(); For an ASP. NET dropdown you can use the following selector: $("id*='MyDropDownId' :selected").

$("#DropDownID").val() will give the selected index value.

Not exactly the answer to the question, but was useful for me. The question wants the selected text. – Peter Nov 28 '11 at 14:50.

Var someName = "Test"; $("#"). Each(function () { $('option', this). Each(function () { if ($(this).text().toLowerCase() == someName) { $(this).

Attr('selected', 'selected') }; }); }); That will help you to get right direction. Above code is fully tested if you need further help let me know.

1: This answers the wrong question. The OP asked how to GET the selected text, not SET by the text. Also, there is no need to have the outer "each" function since selecting by id (#...) implies you'll only ever get a single element.

– Joel Beckham Nov 11 '11 at 17:36.

IHTMLElementCollection Options = (IHTMLElementCollection)droplist. GetElementsByTagName("option"); bool Flag = false; int x = 0; foreach (HTMLOptionElement Option in Options) { x++; if (Flag) { Option. Selected = true; break; } if(x==1) Flag = true; }.

Marked this answer as -1 because the question is about jQuery. Plus, I'm not sure what your code is trying to do. The question wants to get the selected value.

Your code will set the option to be selected. – Peter Nov 28 '11 at 14:45.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions