简体   繁体   中英

Get select option value of a table cell

I have a table with a select option type in a cell. I want to use checkbox such that when it is checked, the cells in this row are shown. I can show the other values in the row but I don't know how to get the select option value.

 $(document).ready(function() { $("#saverecord").click(function(event) { var currentRow = $(".btnSelect:checked").closest("tr"); var col1 = currentRow.find("td:eq(0)").text(); var col2 = currentRow.find("td:eq(1)").text(); var col3 = currentRow.find("td:eq(2)").text(); var data = col1 + "\n" + col2 + "\n" + col3; console.log(data); alert(data); }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table name="mytable" id="mytable"> <tr> <th>year</th> <th>item</th> <th>type</th> <th>checked</th> </tr> <tr> <td>2020</td> <td>shoe</td> <td> <select name="test1" id="test1"> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select> </td> <td><input type="checkbox" class="btnSelect" id="chk" name="chk" /></td> </tr> </table> <input type="button" value="Save the record" id="saverecord" class="button0">

im assuming you are using jQuery, to get the value of your select field:

$("#test1").val()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM