如何将所选数据从模态弹出窗口发送回父窗体并关闭模态

I have in my parent form the following code which opens a modal list view of items.

<?php
    // My Stuff
    $field = $fieldSet['jform_my_stuff'];
    ?>
    <div class="control-group <?php echo 'field-' . $field->id . $field->responsive; ?>">
        <div class="control-label">
            <?php echo $field->label; ?>
        </div>

        <div class="controls">
            <?php echo $field->input; ?>
        <?php
JHTML::_('behavior.modal');
?>
<a class="modal"
<a href="index.php?option=com_popuptry&amp;view=stuff&amp;layout=stuff&amp;tmpl=component" rel="{handler: 'iframe', size: {x: 800, y: 600}}">Select</a>
        </div>

The form looks like this.

Parent Page

The feild I want the data to be updated to is

jform_my_stuff

I have tried a number of options but just cannot get the modal to send back the required input

I replaced all my efforts with some txt for now

Modal

The last peice of code would go in here

</td>
            <?php endif; ?>

            <td style="text-align:center">
                <?php echo JDom::_('html.fly', array(
                    'dataKey' => 'stuff',
                    'dataObject' => $row
                ));?>


            </td>
            <td style="text-align:center">
            Button here to send selected item (stuff) <br>back to parent feild called jform_my_stuff<br> & close modal
            </td>
        </tr>
        <?php
        $k = 1 - $k;
    endfor;
    ?>
    </tbody>
</table>

I am completely lost as to what I need to put in here as most things have not worked.. ?? any pointers appreciated.

You would need to use Javascript. (I use jquery here). I'm doing my best to understand what you are trying to do.

Basically, I'd write a function to handle the button click.

<input type="button" value="Click Me" onclick="sendToMyStuff()">

The function would be as follows:

function sendToMyStuff(){
    var stuff = $('input[name="checkbox"]:checked').val(); // "stuff"
    $('#mystuff').val(stuff); //Sent the value of the stuff input -- if it is not an input you can use .text()
    $('#modal').hide(); //Hide the modal window
}

You could also simply use the ID of the checkbox to get the data. I wasn't exactly sure what you are trying to do. I am also not super familiar with Joomla. You could also just bind the button click.

$('#button').bind('click', function(){ }

Hope this helps.