Sunday, January 11, 2009

Javascript : From Parent to Child

This case is not very well documented.
I found a nice tutorial here :
http://radio.javaranch.com/pascarello/2005/01/18/1106063002000.html

You can download samples here:
FromChildToParent


<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication10._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>

    <script type="text/javascript">
        var w;
        function openPopup() {
            w = window.open("popup.aspx");
            setTimeout("SendToChild()", 200);            
            //This works on FF.
            w.onload = function() {
                alert("child loaded");
            }
        }
        function SendToChild() {
            value = window.document.getElementById("tochild").value;
            w.document.getElementById("fromparent").innerHTML = value;
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="tochild" type="text" runat="server" />
        <span id="opener" title="???" onclick="openPopup()" onmouseover="this.style.cursor='hand'">
            Send To Child</span>
        <hr />
        Child said : <span id="fromchild"></span>
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment