0

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">
halfer
  • 19,824
  • 17
  • 99
  • 186
Jimmy
  • 1
  • 3

1 Answers1

0

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

$("#test1").val()
Karl L
  • 1,645
  • 1
  • 7
  • 11