1

I'm trying to have the parent window open a child window in one case, and then have that window closed in a different case in the parent window:

case "case1": ?>
    <script language="JavaScript" type="text/javascript" src="javascripts.js></script>
    <script>openWin();</script>
    <?php
        $nextDecision ="
                <form action=\"index.php\" method=\"get\">
                <input type=\"radio\" name=\"choice\" value=\"val1\">message<br>
                <input type=\"submit\">
                </form>";  
                ?>
    break;
case "case2": 
    $nextDecision = "
                <form action=\"index.php\" method=\"get\">
                <input type=\"radio\" id=\"choice\" name=\"choice\" onsubmit=\"closeWin()\" value=\"val2\">message<br>
                <input type=\"submit\">
                </form>";
    break;

javascripts.js:

var myWindowwin;

function openWin() {
    myWindowwin = window.open("path/file.html","name","width=547,height=480");
}

function closeWin() {
    document.getElementById('choice').value = 'val2';
    myWindowwin.close();
}

The child window will open, but not close.

5
  • 1
    put the onsubmit on the form not the radio button Oct 15, 2013 at 15:57
  • @scrappedcola I put it in the form: <form action=\"index.php\" method=\"get\" value=\"val1\" name=\"form1\" onsubmit=\"closeWin()\"> but nothing changed. THe window opened but didn't close
    – Jordan
    Oct 15, 2013 at 16:28
  • 1
    Is it on purpose that you're declaring a var called myWindowwin; but later referring to your child window as myWindow?
    – qternion
    Oct 15, 2013 at 19:07
  • @qternion that was my fault from putting the code onto here. Sorry. Just edited it.
    – Jordan
    Oct 15, 2013 at 19:51
  • Some unrelated advice: Use HEREDOC for your multiline string. Then you don't need to escape quotes.
    – Daniel Apt
    Oct 15, 2013 at 21:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.