Tuesday, March 29, 2011

Pass Values among frames/iframe using jQuery - untested - only a snippet

The following is untested code used to assist in a question located here: Link

Parent Document (Main.html)

<!-- parent window (main.html) -->
<input id="inpA" name="inpA" type="text" />
 
<!-- wire this button trigger up to open the dialog -->
<button id="triggerThatOpensDialog">Open Dialog</button>

Child Document (Child.html)

<!-- in the child/popup dialog (child.html) -->
<input id="inpB" name="inpB" type="text" />
<button id="triggerToPopulateParent">Callback to Parent</button>
 
<script type="text/javascript">
    $(function () {
        $("#triggerToPopulateParent").click(function (e) {
            e.preventDefault();
            // text input on the child/popup
            var $inputOnChild = $("#inpB");
 
            // text input on the parent that opened the child/popup
            var $inputOnParent = $("#inpA", window.opener.document);
 
            // set the parent textbox value using the child textbox value
            $inputOnParent.val($inputOnChild.val());
        });
    });
</script>

No comments:

Post a Comment