最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get the value form dropdown using Jquery - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Jun 17, 2014 at 7:35 V.V asked Jun 17, 2014 at 7:16 V.VV.V 8833 gold badges25 silver badges56 bronze badges 2
  • 2 would be great if you can share html too – Milind Anantwar Commented Jun 17, 2014 at 7:17
  • 1 $(this).closest('tr').find('select'), there's no input[type="select"] – billyonecan Commented Jun 17, 2014 at 7:21
Add a ment  | 

6 Answers 6

Reset to default 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'.

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);
}

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();

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();
});

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

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.

发布评论

评论列表(0)

  1. 暂无评论