How to pass data value from Bootstrap Modal to Parent form
<p>How to pass data attribute or click event from Bootstrap modal to parent form/window.</p>

<p>for example,
On clicking the below input box, the modal will popup with divs having data attribute</p>

<pre><code>&lt;input type="text" name="menu_image_id" class="form-control" data-toggle="modal" data-target=".show_modal_w" /&gt;

&lt;input type="text" name="menu_image_id_2" class="form-control" data-toggle="modal" data-target=".show_modal_w" /&gt;
</code></pre>

<p>Modal window</p>

<pre><code>&lt;div class="modal fade show_modal_w" tabindex="-1" role="dialog"&gt;
    &lt;div class="modal-dialog modal-lg" role="document"&gt;
        &lt;div data-id="1"  data-dismiss="modal"&gt;Hello&lt;/div&gt;
        &lt;div data-id="2"  data-dismiss="modal"&gt;Welcome&lt;/div&gt;
        &lt;div data-id="3"  data-dismiss="modal"&gt;Morning&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Now when the user clicks the div inside the modal for example either Hello, Welcome or Morning, then we need to pass the id value from modal to parent input box with name menu_image_id.</p>

<p>I tried using the below close function, but not able to get the modal data id to parent window.</p>

<pre><code>$('.show_modal_w').on('hidden.bs.modal', function (e) {
    $(e.relatedTarget);
})
</code></pre>