title: Opening a modal window with onclick of a button with preset form field value
body: <p>I have a button called view. On clicking the view button, a modal window should pop up with a given value</p>
  
  <p>Below is the code for for view button which pops a modal with empty body. </p>
  
  <pre><code>&lt;a role="button" class="btn btn-sm btn-primary" href="#time_line" data-toggle="modal"&gt;View&lt;/a&gt;
  </code></pre>
  
  <p>Modal div:</p>
  
  <pre><code>&lt;div id="time_line" class="modal fade" tabindex="-1"&gt;
          &lt;div class="modal-header" style="background: #045e9f;"&gt;
              &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
              &lt;h4 class="white bigger"&gt;Initiate Order&lt;/h4&gt;
          &lt;/div&gt;
  
          &lt;div class="modal-body overflow-visible"&gt;
              &lt;form&gt;
                  &lt;input type="text" name="t_val" id="t_val"&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  
          &lt;div class="modal-footer"&gt;
              &lt;button class="btn btn-small" data-dismiss="modal"&gt;
                  &lt;i class="icon-remove"&gt;&lt;/i&gt;
                  Close
              &lt;/button&gt;
          &lt;/div&gt;  
  &lt;/div&gt;
  </code></pre>
  
  <p>How do I pass a value to the val field in the modal upon the modal pop</p>
  
  <p><strong>Answer:</strong></p>
  
  <p>Hi, I did the following and got what I want</p>
  
  <pre><code>function pass_data(data)
  {
      $('[name="t_val"]').val(data);
  }
  
  &lt;a role="button" class="btn btn-sm btn-primary" href="#time_line" data-toggle="modal" onclick= "pass_data($data)"&gt;View&lt;/a&gt;
  </code></pre>
  
  <p>A slight change to the answer by DarkseidNG</p>