2011-01-10 131 views
0

我想將checkoxes中的多個值從子窗口傳遞給父窗口。將值從子窗口傳遞給父窗口

但是,我可以將單個複選框的單值傳遞給父窗口。

但是,當我宣佈在子窗口中的兩個複選框,父窗口顯示不定值

子窗口代碼:

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

請諮詢

+0

您的「子窗口」是否在iframe中? – polarblau 2011-01-10 13:22:57

+0

我不明白你的問題,請更多解釋。 – 2011-01-10 13:24:07

回答

1

嘗試分配的多個複選框的ID,做它這樣:

<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(); 
} 

...它也可能Ë你缺少賦值到子窗口中的複選框,但我想這是不可能的,因爲它有一個單一的一個

1

這裏是一個腳本發送用戶名和密碼的父窗口的工作原理:

<!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> 
相關問題