How to pass data-key value of clicked Table row when click on Button

Viewed 10434

I have a table with some rows and each tow has an data-key value. Now I select one of those rows and want to click on a button in order to forward this data-key value as an GET value. I don't really know how to capture this selected data-key. Kindly asking for help.

Here is a fiddle: fiddle

Below is my snippet so far.

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />

<div class="container-fluid">
  <div class="form-horizontal" style="margin-top:5em;">
    <div class="input-group">
      <input class="form-control form-control-sm" id="FunctionBookSearchForEvents" placeholder="Search for Events" style="font-size:12px;">
      <button class="btn btn-sm btn-secondary" href="events.phtml?TableID=''" data-id="" style="margin-left:1em; font-size:12px;">Add Event</button>
    </div>

    <div id="Table">
      <table class="table table-sm table-hover">
        <thead>
          <tr>
            <th>ID</th>
            <th>Event Name</th>
          </tr>
        </thead>
        <tbody>
          <tr class="clickable-row" data-key="12">
            <td>12</td>
            <td>Test Event 12</td>
          </tr>
          <tr class="clickable-row" data-key="13">
            <td>13</td>
            <td>Test Event 13</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>

1 Answers
Related