开发者

passing values from child to parent window

I want to pass multiple values in checkoxes from the child window to parent window.

However, I am able to pass single value of single checkbox to parent window.

But when I declare two checkboxes in child w开发者_如何学运维indow, the parent window shows undefined value

Child Window Code:

function post_value(){
   opener.document.cat_tree.catselected.value = document.frm.child_name.value;
   self.close();
}

Kindly Advice


try assigning those multiple checkboxes an ID and doing it this way:

<input type="checkbox" name="child_name_1" id="child_name_1" value="value1" />
<input type="checkbox" name="child_name_2" id="child_name_2" value="value2" />

...

function post_value(){
    var all_values = '';
    all_values += document.getElementById('child_name_1').value;
    all_values += ', '+document.getElementById('child_name_2').value;
    opener.document.cat_tree.catselected.value = all_values;
    self.close();
}

... it is also possible that you're missing to assign values to your checkboxes in the child window, but I guess that is unlikely since it works with a single one


Here is a script to send username, and a password to the parent window:

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" >
            function post_value(){
                var all_values = '';
                all_values += 'id='+document.getElementById('id').value;
                all_values += '&username='+document.getElementById('username').value;
                all_values += '&password='+document.getElementById('password').value;
                window.opener.location='listing.php?'+all_values;
                self.close();
            }
        </script>

        <style type="text/css">
            body { background-color:#b0c4de; }
        </style>
    </head>

    <body>
        <form method="POST">
            <input type="hidden" id="id" name="id" value="<?=$_GET['id']?>">
            <h2>Log-In</h2>
            <p>Username:</p><input type="text" id="username" name="username">
            <p>Password:</p><input type="text" id="password" name="password">
            <input type="submit" name="login" Value="Log-In" onClick="post_value();" />
        </form>
    </body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜