Question

I have a table containing dropdown list in each row. Rows doesn't have id property. So, as row doesn't have id property, how can i get selected item of the dropdown list and corresponding ID column's value. for example, if i select an item from the first row i want value of the item and ID column's value, i.e. 204.

table to be manipulated using jQuery

This is the html code of the above table

 <table class="table-1 gapmb40">
    <thead>
        <tr>
            <th>
                Status
            </th>
            <th>
                <a class="sortable" href="">Featured</a>
            </th>
            <th>
            </th>
            <th>
                <a class="sortable" href="">Date Modified</a>
            </th>
            <th>
            </th>
            <th>
                ID
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <select class="input-2" name="2">
                    <option value="New">New</option>
                    <option selected="selected" value="Live">Live</option>
                    <option value="AccountOnly">AccountOnly</option>
                    <option value="Hide">Hide</option>
                    <option value="Suspended">Suspended</option>
                </select>
            </td>
            <td>
                <a href="">Feature</a>
            </td>
            <td>
                <a href="">View</a>
            </td>
            <td>
                07/03/2013
            </td>
            <td style="display: none">
                <a href="">LogOnAs</a>
            </td>
            <td>
                204
            </td>
        </tr>
    </tbody>
</table>

No correct solution

OTHER TIPS

give all you selectbox a class...say selectClass and use jquery class selector.

try this

 $('.selectClass').change(function(e){
     alert($(this).val()); //gives you the selected value
     alert($(this).parents('tr').find('td:eq(5)').text()); //gives you the related TD which is 4th column and gets its text

     //or
     alert($(this).closest('tr').find('td:eq(5)').text()); 
});

fiddle here

<select onchange=sel_change(this.value,'<%=id%>');></select>

so in the javascript function you can get the selected item value and the id of that row

<script>

    function sel_change(item,id){
        alert("selected item "+item+"from the id "+id);
    }

</script>

If you have table id then you can try this..

$("#tbltable tr").click(function() {
    var selectedText = $(this).find('select :selected').text();
    var columnID = this.cells[4].innerHTML.toString();
    alert(selectedText + " , " + columnID);
 });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top