title: Create a link using jquery and variables returns undefined
body: <p>I'm trying to create a link using JQuery and some JS variables. The HTML is as follows:</p>
  
  <pre><code>    &lt;script&gt;
      $(document).on("click", ".btn", function () {
           var $memberid = $(this).data("id");
           var $memberName = $(this).data("name");
           $(".modal-body #memberName").text($memberName);
           $(".modal-footer a").attr("href","/user/delete/" + $memberid);
      });
  &lt;/script&gt;
  
  &lt;div class="panel panel-default"&gt;
    &lt;div class="panel-heading"&gt;All Users&lt;/div&gt;
    &lt;div class="panel-body"&gt;
      &lt;table class="table"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Operating Capacity&lt;/th&gt;
              &lt;th&gt;Actions&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          @foreach ($users as $user)
          &lt;tr&gt;
              &lt;td&gt;{{ $user-&gt;fname }} {{ $user-&gt;lname }}&lt;/td&gt;
              &lt;td&gt;{{ $user-&gt;user_type-&gt;name }}&lt;/td&gt;
              &lt;td&gt;
              @if($user-&gt;position &lt; 4)
              &lt;a href="/user/profile/{{ $user-&gt;memberid }}" class="btn btn-sm btn-primary"&gt;Edit&lt;/a&gt; 
              &lt;button type="button" class="btn btn-sm btn-danger" data-id="{{ $user-&gt;memberid }}" data-name="{{ $user-&gt;fname }} {{ $user-&gt;lname }}" data-toggle="modal" data-target="#myModal"&gt;Delete&lt;/button&gt;
              @endif
              &lt;/td&gt;
          &lt;/tr&gt;
          @endforeach
      &lt;/tbody&gt;
      &lt;/table&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;!-- Modal --&gt;
  &lt;div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"&gt;
    &lt;div class="modal-dialog" role="document"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
          &lt;h4 class="modal-title" id="myModalLabel"&gt;Delete User&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
          &lt;p&gt;Are you sure you wish to delete this user?&lt;/p&gt;
          &lt;p id="memberName"&gt;&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;a href="" class="btn btn-danger wideButton"&gt;Yes&lt;/a&gt; 
          &lt;button type="button" class="btn btn-success wideButton" data-dismiss="modal"&gt;No&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Now this creates the link just fine. When the modal screen opens the 'Yes' button has a link to </p>
  
  <blockquote>
    <p>/user/delete/someuserid</p>
  </blockquote>
  
  <p>But the minute you click the link it returns a URL like </p>
  
  <blockquote>
    <p>/user/delete/undefined</p>
  </blockquote>
  
  <p>Any ideas where I'm going wrong? I assume it is to do with variable scope but I can't put my finger on where.</p>
  
  <p>Many Thanks</p>
  
  <p>Gavin.</p>