Dinesh
Dinesh

Reputation: 73

JQuery get select element inside table

I have the following table element which has a select element in its td. The table id (table1 in the example) can keep changing. So, how can I fetch the selected option using table ID in JQuery?

    <table class="indexViews" id = "table1">
   <tr>
    <td align="center", width="10%" valign="middle"></td>
    <td align="center", width="70%" valign="middle">
        <select  id="indexViewsList" class="indexViewsListWnd" onChange="switchIndexView(this)">
            <option id="0" value="0" selected="selected">Index Quick View</option>
            <option id="1" value="1">Identifier View</option>
            <option id="2" value="2">Commodity</option>
        </select></td>
    <td align="right", width="10%" valign="middle"><input class="searchIcon" type="image" src="../../images/downloadIcon.gif" alt="Submit" onClick="downloadIndexFile()"></input></td>
   </tr>
</table>

Upvotes: 0

Views: 7595

Answers (4)

Irfan TahirKheli
Irfan TahirKheli

Reputation: 3662

This is how you get it using table id.

$('#table1 #indexViewsList').val();

But better you get this select directly:

$('#indexViewsList').val();

Upvotes: 1

Andr&#233;s Torres
Andr&#233;s Torres

Reputation: 733

You can use this selector in jQuery $('table[id^="table"]')

Jquery - "Attribute starts with" selector

Upvotes: 1

Gautam
Gautam

Reputation: 3386

try below code

var selectedValue= $(".indexViews .indexViewsListWnd").val();

Upvotes: 1

Francis
Francis

Reputation: 367

I don't understand why your id keep changing. But maybe you will want to iterate through your table using jquery selector on class name.

var lstIndexView = $(".indexViews .indexViewsListWnd");

http://api.jquery.com/class-selector/

Upvotes: 2

Related Questions