无法将javascript函数/变量从一种情况传递到另一种情况

无法将javascript函数/变量从一种情况传递到另一种情况,javascript,php,html,function,parent-child,Javascript,Php,Html,Function,Parent Child,我尝试让父窗口在一种情况下打开子窗口,然后在父窗口中的另一种情况下关闭该窗口: case "case1": ?> <script language="JavaScript" type="text/javascript" src="javascripts.js></script> <script>openWin();</script> <?php $nextDecision ="

我尝试让父窗口在一种情况下打开子窗口,然后在父窗口中的另一种情况下关闭该窗口:

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;

子窗口将打开,但不会关闭。

将onsubmit放在表单上,而不是收音机上button@scrappedcola我把它写在表格里,但没有任何变化。窗口已打开但未关闭是否是有意声明一个名为myWindowwin的变量;但后来将您的子窗口称为myWindow?@qternion,这是我将代码放在这里的错误。很抱歉刚刚编辑过。一些无关的建议:用于多行字符串。那么你就不需要转义引号了。
var myWindowwin;

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

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