title: Only the button on the first row is working in a table
body: <p>I have an MVC Application that returns items from the model and there is a button added on the table to each row, the problem is that only the first item that is working perfectly the rest doesn't even call the method. I have done my research with no luck. here is the code on my view. is there something that I am doing wrong? Please help.</p>
  
  <pre><code>&lt;section class="container"&gt;
      &lt;section class="panel"&gt;
          &lt;section class="panel-heading panel-border-danger "&gt;
              &lt;h2 class="panel-heading-text "&gt;
                  &lt;i&gt;&lt;/i&gt;  Script Management
              &lt;/h2&gt;
          &lt;/section&gt;
          &lt;link href="~/Content/Site.css" rel="stylesheet" /&gt;
     &lt;section &gt;
  
              &lt;table class="table table-responsive" id="tblScripManager"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.scriptName)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.logFileName)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.Active)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.AllowToRun)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.scriptdescription)
                          &lt;/th&gt;
                          &lt;th&gt; Last Run &lt;/th&gt;
                          &lt;th&gt; Time Taken&lt;/th&gt;
                          &lt;th&gt; Errors &lt;/th&gt;
                          &lt;th&gt; Re-Run &lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      @foreach (var item in Model)
                      {
                          &lt;tr&gt;
  
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.scriptName)
                              &lt;/td&gt;
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.logFileName)
                              &lt;/td&gt;
  
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.Active)
                              &lt;/td&gt;
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.AllowToRun)
                              &lt;/td&gt;
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.scriptdescription)
                              &lt;/td&gt;
  
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.lastRun)
                              &lt;/td&gt;
  
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.timeTaken)
                              &lt;/td&gt;
  
                              @if (item.Errors == "No Errors")
                              {
                                  &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Errors)&lt;/td&gt;
  
                              }
                              else
                              {
                                  &lt;td style="cursor:pointer"&gt; &lt;a id="myBtn" class="btn-group"&gt;@Html.DisplayFor(modelItem =&gt; item.Errors)&lt;/a&gt;&lt;/td&gt;
                              }
  
                              &lt;td&gt;
                                  &lt;input id="btnRun" type="button" value="Run Script" onclick="location.href='@Url.Action("Script", "RunScript")?id=' + document.getElementById('@item.scriptId').value" /&gt;
  
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;div id="myModal" class="modal"&gt;
  
                              &lt;!-- Modal content --&gt;
                              &lt;div class="modal-content" style="padding-top: 10px; padding-left: 10px; padding-right:30px; left: 50px; top: 70px; width: 70%; height: 50%; "&gt;
                                  &lt;span class="close"&gt;&amp;times;&lt;/span&gt;
                                  &lt;p style="line-break:strict"&gt;@Html.DisplayFor(modelItem =&gt; item.ErrorList)&lt;/p&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      }
                  &lt;/tbody&gt;
              &lt;/table&gt;
          &lt;/section&gt;
  
      &lt;/section&gt;
  
  &lt;/section&gt;
  
  
  
  &lt;script&gt;
  
      $(document).ready(function () {
          $("#btnRun").click(function () {
              $.getJSON('@Url.Action("RunScript")', { scriptId: '4' }, function (data) {
                  console.log(data);
                  //$("#run").val(data);
              });
          });
  
      });
  
  
      // Get the modal
      var modal = document.getElementById('myModal');
  
      // Get the button that opens the modal
      var btn = document.getElementById("myBtn");
  
      // Get the &lt;span&gt; element that closes the modal
      var span = document.getElementsByClassName("close")[0];
  
      // When the user clicks the button, open the modal
      btn.onclick = function () {
          modal.style.display = "block";
      }
  
      // When the user clicks on &lt;span&gt; (x), close the modal
      span.onclick = function () {
          modal.style.display = "none";
      }
  
      // When the user clicks anywhere outside of the modal, close it
      window.onclick = function (event) {
          if (event.target == modal) {
              modal.style.display = "none";
          }
      }
  
      $('.modal').click(function () {
          $('#my-dialog').load(this.href, function () {
              $(this).dialog('open');
          });
          return false;
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>`</p>