1

Here is what I want to do.

In the first row that has tds then a = the text in the first cell and b = the selected value of the drop down that the user selected

How do I do this as my code is not working?

$(document).ready(function () {
   var s = $('table td:first').parents('tr');

   var a = s.eq(0).text();
   var b = s.eq(1).find('option:selected').val();

   alert(a + "   " + b);
});

<table>
   <tbody>
      <tr>
         <th>ID</th>
       </tr>
       <tr>
          <td>
            test
           </td>
           <td>
             <select>
               <option value="yes">yes</option>
               <option selected="selected" value="no">no</option>
             </select>
           </td>
        </tr>
    </tbody>
</table>
yogi
  • 19,175
  • 13
  • 62
  • 92
Hello-World
  • 9,277
  • 23
  • 88
  • 154
  • Check out these links hope it helps you...http://stackoverflow.com/questions/5866862/how-to-get-the-data-from-a-row-jquery http://stackoverflow.com/questions/10147971/jquery-getting-values-from-selected-table-row http://forums.asp.net/t/1652535.aspx – Mayank Pathak Jul 31 '12 at 09:37

3 Answers3

2

Working demo http://jsfiddle.net/snU97/

Rest feel free to play around, & hope it helps your needs :)

code

$(document).ready(function () {

    var s = $('table td:first').parents('tr');

    var a = s.find('td').eq(0).text();//s.eq(0).text();
    var b = s.find('td').eq(1).find('option:selected').val();

    alert(a + "   " + b);

});​
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
1

You can Also Use the Following Code

$(document).ready(function () {

var s = $('table td:first');

var a = s.html();
var b = s.parents('tr').children().find('option:selected').val();

alert(a + "   " + b);

});

Sumit Neema
  • 462
  • 3
  • 18
1

there is an option :

    <table>
        <tbody>
            <tr>
                <th>ID</th>
            </tr>
            <tr>
                <td>
                    test
                </td>
                <td>
                    <select id="mydropdown">
                        <option value="yes">yes</option>
                        <option selected="selected" value="no">no</option>
                    </select>
                </td>
            </tr>
        </tbody>
    </table>​​​



$(document).ready(function () {

    var s = $('table td:first');

    var a = s.text();
    var b = $("#mydropdown option:selected").text();

    alert(a + "   " + b);

});​
cedric
  • 302
  • 1
  • 12