Hi all,


How can i get the value of a specific text in a select box.

example 16 of text OEC using jquery,

I am not getting the value correctly

<select name="categories" id="categories" class="validate">
<option value="0" selected="selected">&lt;--select one--&gt;</option>
<option value="57">OBC</option>
<option value="16">OEC</option>
</select>


I had tried For example something like $("#categories option[text='OEC']").val(); but not getting the value. Is there any mistake or is it possible.

Try to use:

$("#categories :selected").text();

Or something like this:

$("#categories").each( function() {
    if ($(this).text == "OEC") {
        alert ($(this).val());
   }
});

is that what you mean?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.