Re: Undefined JS variables when loading dialogs

  •  03-25-2011, 11:14 AM

    Re: Undefined JS variables when loading dialogs

    Dear zBrain,
     
    Please follow steps:
     
    1. Save the following code to dad.html
    <HTML>
    <HEAD>
    <SCRIPT>
        function popupCuteEditor(v_form, v_field) {
            var newWin, v_pagestring;
            w = 770;
            h = 500;
            LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
            TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
            settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=';
            v_pagestring = "kid.php?form=" + v_form + "&field=" + v_field;
            newWin = window.open(v_pagestring, "HTMLEdit", settings + LeftPosition + 'resizable=yes')
        }
    </SCRIPT>
    <TITLE>Parent Page</TITLE>
    </HEAD>
    <body>
     <FORM name="f1" id="f1" method=POST target='kid'>
      <textarea name="t1" cols="100" rows="15">Text Area 1 Text</textarea><br/>
      <input type="button" value="Edit In CuteEditor" name="B1"  onclick="popupCuteEditor('f1','t1')">
     </FORM>
    </BODY>
    </HTML>
    2. Save the following code to kid.php
    <?php include_once("cuteeditor_files/include_CuteEditor.php") ; ?>
    <html>
    <head>
    <TITLE>Kid Child Window</TITLE>
    </head>
    <body bottomMargin="0" topMargin="0" marginwidth="0" marginheight="0"
     onload="setTimeout(getparentdata,1000);" bgcolor="#efefef">

    <FORM name="fkid" method=POST>
     <h1>Enable All Toolbars</h1>
     <p>This example shows you all the predefined buttons.</p>
     <br />
     <?php
     $editor=new CuteEditor();
     $editor->ID="Editor1";
     $editor->Text="Type here";
     $editor->EditorBodyStyle="font:normal 12px arial;";
     $editor->EditorWysiwygModeCss="php.css";
     $editor->Draw();
     $editor=null;
     
     //use $_POST["Editor1"]to retrieve the data
     ?> <br />
     <INPUT type="button" value='Get Parent data' onClick="getparentdata();">
     <INPUT type="button" value='Set Parent value'
      onClick="tellDad(); window.close();"> <br />
     </form>
    <script type="text/javascript">
      // querystring
      // Call function by x = querystring("variable") returns variable=x
            function querystring(key)
      {   
       var value = null;
       for (var i=0;i<querystring.keys.length;i++)
       {
       if (querystring.keys[i]==key)
       {
       value = querystring.values[i];
       break;
       }
       }
       return value;
      }
      querystring.keys = new Array();
      querystring.values = new Array();
      function querystring_parse()
      {
       var query = window.location.search.substring(1);
       var pairs = query.split("&");  
       for (var i=0;i<pairs.length;i++)
       {
        var pos = pairs[i].indexOf('=');
        if (pos >= 0)
        {
        var argname = pairs[i].substring(0,pos);
        var value = pairs[i].substring(pos+1);
        querystring.keys[querystring.keys.length] = argname;
        querystring.values[querystring.values.length] = value;
        }
       }
      }  
      querystring_parse();
      // Set the parent windows form and field to a variable
      var v_parentform, v_field, v_form;
      v_field = querystring("field");
      v_form = querystring("form");
      var v_parent = "window.opener.";
      v_parentform = eval(v_parent + v_form);   
      function tellDad()
      {
       var editor1=document.getElementById('CE_Editor1_ID');
       var editdoc = editor1.GetDocument(); 
       v_parentform.elements[v_field].value=editdoc.body.innerHTML;
      }
      function Onload()
      {
       getparentdata();
       resizeWindow();
      }

      function getparentdata()
      { 
       var editor1=document.getElementById('CE_Editor1_ID');
       var editdoc = editor1.GetDocument(); 
       editdoc.body.innerHTML = v_parentform.elements[v_field].value;
      }

      function resizeWindow() {
       var iWidth = 720 + 18;
       var iHeight = 380 + 44;
       window.resizeTo(iWidth,iHeight)
      }
     </SCRIPT>
    </body>
    </html>

    3. Open dad.html, and have some test.
     
    Thank you for asking
View Complete Thread