Topic: Retrieve the text string from the selected option in a select dropdown

AJEsler2019 priority asked 3 years ago


Expected behavior

I want to retrieve the text string from the selected option of a select dropdown generated from an AJAX call. The options returned in the ajax call include an item name and quantity available in the text and a part number as the option value. I want to slice the quantity available from the text for use in a calculation. In the select options below, if I select the second dropdown item, I want to retrieve the text "Item Two - 7 available"

Resources (screenshots, code snippets etc.)

Item One - 2 available

Item Two - 7 available

Item Three - 12 available


Tomek Makowski staff answered 3 years ago


Hi

Could you show your code in snippet editor?

Regards


AJEsler2019 priority commented 3 years ago

I managed to find the way to achieve this using the following (this was the important bit - find("option:selected").text() ) var fromButton = $('#consumeFrom').find("option:selected").text(); var startPos = fromButton.search("units available") + 16; var endPos = fromButton.length; var availableQty = fromButton.slice(startPos,endPos);


Tomasz Makowski free commented 3 years ago

Happy you found out the solution. Regards.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB jQuery
  • MDB Version: 4.18.0
  • Device: PC
  • Browser: Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No