Tip: If the value property is not specified for an option element, then the text content will be sent to the server when the container form is submitted. In the example code, we will show how you can get the text value of the select using jQuery. Note: For select menus, the change event occurs when an option is selected. Answer: Use the jQuery :selected Selector. The change() method triggers the change event, or attaches a function to run when a change event occurs.

The following select box has some options with values, the text value of the selected option will be retrieved from this select element. I want to be able to set the selected attribute on a dropdown menu based on the option text NOT value. < option value = "5" > Prof If you wanted to get the string "Mr" if the first option was selected (instead of just "1") you would do that in the following way: Changing a select option without JQuery.

Definition and Usage.

The change event occurs when the value of the element is changed. So I have a dropdownlist, and I know that I can set the selected option by the .val() function, as in, $('#MySelect').val("12345"); if there is an option Setting selected option in dropdownlist by the text, not value - jQuery Forum using jQuery are mentioned in this article.

In the below function we are using the select option id. You will get the output in the div element using the jQuery html(). You can use the jQuery :selected selector in combination with the val() method to find the selected option value in a select box or dropdown list. When we have the option value, so use the CSS Attribute selector, and .attr() $( ).find( ' option[value=""]' ).attr( ' selected' , ' selected' ) To fetch the index (position of the option in DOM tree) of an option by its value, use:

However, you can also get this output in the alert message as per your requirement.

The change event occurs when the value of an element has been changed (only works on ,