1

I use the following jquery function for get the drop down value in a table row.But its not give the value.

HTML

<select id='statusprocess'><option value='optSelected'>Selected</option><option value='optNotSelected'>Not Selected</option></select>

JQUERY

     var select = $(this).closest('tr').find('input[type="select"]').map(function () {
                    return this.text();
                }).get();

How to find the dropdown and get selected option text?

Answer Is:

This is the Exact way to find the dropdown in Table and get selected the Selected Text.

var select = $(this).closest('tr').find('select option:selected').text();

It was Working Fine Now.

2
  • 2
    would be great if you can share html too Commented Jun 17, 2014 at 7:17
  • 1
    $(this).closest('tr').find('select'), there's no input[type="select"] Commented Jun 17, 2014 at 7:21

6 Answers 6

1

Since you have the ID already, why don't you just get it via the ID?

$("#statusprocess").val();

The above statement returns 'optSelected' or 'optNotSelected'.

Or else if you were referring to the "option text" instead of the "option value", you can try this.

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

The statement above returns 'Selected' or 'Not Selected'.

Sign up to request clarification or add additional context in comments.

Comments

0

i think you can simply get it by

$("#statusprocess").val()

HTML

<select id='statusprocess' onChange="getIt()"><option value='optSelected'>Selected</option><option value='optNotSelected'>Not Selected</option></select>

SCRIPT

function getIt(){
var i=$("#statusprocess").val()
alert(i);
}

Comments

0

Depending on what you want to get, you can either get the value:

$("#statusprocess").val();

or the text of the selected

$("#statusprocess option:selected").text();

Comments

0

you can get the value of dropdown when the value changes. so use change method to get the value when option changes. JQuery Doc

$('input[type="select"]').change(function(){

var value = $( "select option:selected" ).text();
});

Update

you can just fetch the value by using the class also.

$(".selectboxClass").on('change',function(){
var value = $( ".selectboxClass option:selected" ).text();
});

Comments

0

There is no input[type=select] exist.

Your dropdown list is a <select> element, not an <input type="select" />. So you should use the select instead of using input[type = "select"].

Selected option value:

$(this).closest('tr').find('#statusprocess').val();

Selected option text:

$(this).closest('tr').find('#statusprocess option:selected').text();

Working Example

OR if you have single dropdown inside the tr, you can also use element selector (i.e select) this:

Selected option value:

$(this).closest('tr').find('select').val();

Selected option text:

$(this).closest('tr').find('select option:selected').text();

Working Example

Comments

0

This is the Exact way to find the dropdown in Table and get selected the Selected Text.

var select = $(this).closest('tr').find('select option:selected').text();

It was Working Fine Now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.