Popup window taking variables from its opener

Discussion in 'JavaScript' started by Submerged, Mar 8, 2008.

  1. #1
    I'm trying a three page system to check if a username has been registered already. I'm having trouble on the second page, which is what I need help with. The code I have so far is:

    Page one (registration page):
    <head><script type="text/javascript">
    function myPopup() {
    window.open("checkusername.php", "popUp", "status = 1, height = 300, width = 300, resizable = 0" )}
    </script></head>
    <body>
    <p onClick="myPopup()">CLICK ME!</p>
    <form name=myform>
    <input name=username type=text value='hi!'>
    </form></body>
    Code (markup):
    Page 2 (checkusername.php) takes whatever is in the "username" input on the original page and puts it in the input on it's own page (also named "username").
    <head>
    <script>
    document.myform.username.value = opener.myform.username.value;
    </script>
    </head>
    
    <form name='myform' action='checkusername2.php' method='post'>
    <input type='text' name='username' value=''>
    </form>
    Code (markup):
    So far, the popup opens just fine and displays the username input, but the value doesn't transfer. Javascript is not my strong point, so any help would be awesome here :)

    -Submerged

    PS. Someone might notice I posted this in the HTML section as well, I didn't see a Javascript in that area and didn't think about it being in the same area as PHP :)
     
    Submerged, Mar 8, 2008 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    That code must be generating an error, because it runs before the form has been rendered.
    window.onload=function(){document.myform.username.value = opener.myform.username.value;}
    Code (markup):
     
    Logic Ali, Mar 8, 2008 IP
  3. Submerged

    Submerged Active Member

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Ah, that worked great. Thanks :)
    -Submerged
     
    Submerged, Mar 8, 2008 IP