Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    controlling form foelds from previous window

    I got this two part script from here - http://developer.irt.org/script/165.htm

    I've inserted the first bit in one of my web pages and it seems to work. Well it opens the correct form in the new window. But where do I put the second bit of the script? In the form page or as part of the script in the original page?

    What tags do I put it in too?


    If one window opens another:

    <script language="JavaScript"><!--
    function newWindow(file,window) {
    msgWindow=open(file,window,'resizable=no,width=200,height=200');
    if (msgWindow.opener == null) msgWindow.opener = self;
    }
    //--></script>

    <form>
    <input type="button" value="Open New Window" onClick="newWindow('a.html','window2')">
    </form>




    To access the contents of a form field in new window from the original window:

    var myVar = msgWindow.document.formName.formFieldName.value;



    It's this last line that i dunno where to put or what tags to put it in etc.
    Thanx mucho.

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    176
    Thanks
    0
    Thanked 0 Times in 0 Posts
    heres a demo:

    file one: the popup (save it as popup.htm)
    Code:
    <html>
    <head>
    <title>Window2</title>
    </head>
    <body>
    <p>
    Step Two:
    </p>
    <form name="frmPopup">
    Enter First Name:
    <br />
    <input type="text" name="txt1" />
    <br />
    Enter Surname:
    <br />
    <input type="text" name="txt2" /> 
    </form>
    (minimise this window)
    </body>
    </html>
    file two: the main window
    Code:
    <html>
    <head>
    <title>Main Window</title>
    <script type="text/jav&#97;script" language="jav&#97;script">
    <!--;
    function newWindow(file,window) {
        msgWindow=open(file,window,'resizable=no,width=200,height=200');
        if (msgWindow.opener == null) msgWindow.opener = self;
    }
    
    //to access form contents in the popup
    function accessCont(){
    //var myVar = msgWindow.document.formName.formFieldName.value;
    var fldOne = msgWindow.document.frmPopup.txt1.value;
    var fldTwo = msgWindow.document.frmPopup.txt2.value;
    alert("Field One: " + fldOne + "\nField Two: " + fldTwo)
    }
    //-->
    </script>
    </head>
    <body>
    <form>
    Step One:
    <br />
    <input type="button" value="Open New Window" 
    onClick="newWindow('popup.htm','window2')" />
    <br />
    Step Three:
    <br />
    <input type="button" value="Access Popup Form" 
    onclick="accessCont()" />
    </form>
    </body>
    </html>
    Last edited by HairyTeeth; 04-05-2003 at 08:25 PM.

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Thanx Hairyteeth.

    I've created the two pages using copy and paste. When I click the buttons nothing happens escept that the status bar starts showing 'error on page' Have I omitted to do something?

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Make sure you unwrap this line:

    msgWindow=open(file,window,'resizable=no,width=200
    ,height=200');


    It should all be on one line...
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •