0

I have the following jQuery code, to get the text of the selected option inside a drop-down field:-

var selectobject = $("select[id*='ResponsibilitySubCategory']");
var currentsubcat = selectobject.selected.text();

but i am getting this error:-

"TypeError: selectobject.selected is undefined"
John John
  • 1
  • 72
  • 238
  • 501
  • `selected` isn't a property of jquery – Vencovsky Mar 19 '19 at 15:01
  • @Vencovsky ok i see , so how i can get the text of the selected option then? – John John Mar 19 '19 at 15:05
  • check [this](https://learn.jquery.com/using-jquery-core/faq/how-do-i-get-the-text-value-of-a-selected-option/) and [this](https://api.jquery.com/selected-selector/) – Vencovsky Mar 19 '19 at 15:06
  • Possible duplicate of [this](https://stackoverflow.com/questions/1643227/get-selected-text-from-a-drop-down-list-select-box-using-jquery) – Vencovsky Mar 19 '19 at 15:07
  • Possible duplicate of [Get selected text from a drop-down list (select box) using jQuery](https://stackoverflow.com/questions/1643227/get-selected-text-from-a-drop-down-list-select-box-using-jquery) – Renan Araújo Mar 19 '19 at 15:55

1 Answers1

0

Try this:

var selectobject = $("#myselect :selected");
var currentsubcat = selectobject .text()

For an ASP.NET dropdown you can use the following selector:

$("[id*='MyDropDownId'] :selected")
Vencovsky
  • 28,550
  • 17
  • 109
  • 176
  • but in my case i already have the first selector as `var selectobject = $("select[id*='ResponsibilitySubCategory']");` – John John Mar 19 '19 at 15:14
  • please do a `console.log($("select[id*='ResponsibilitySubCategory']");)` and show me what you see – Vencovsky Mar 19 '19 at 15:17