2012-03-30 24 views
0

我試圖從通過jQuery對話框加載的頁面中檢索選定的值。從jQuery對話框中加載的頁面中檢索選定的值

以下是詳細信息 - 一旦SelectTeam.php頁面已加載到對話框(已通過一些默認選擇),一旦用戶單擊對話框的「確定」按鈕,我想檢索新選擇,因爲用戶可以覆蓋默認選擇&,然後按確定。如何在按下「確定」按鈕時獲得新的選擇。

父頁 - 這是在jQuery的對話框加載

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
    <title>jQuery UI Dialog Example</title> 
    <link type="text/css" href="css/smoothness/jquery-ui-1.8.18.custom.css" rel="stylesheet" /> 
    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> 
    <script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script> 
    <style> 
      body { font-size: 62.5%; } 
    </style> 
    <script type="text/javascript"> 
     function openDialog(url) { 
      $("#somediv").load(url).dialog({ 
              modal:true, 
              title: 'Team Select', 
              width: 300, 
              height: 400, 
              autoOpen: true, 
              resizable: false, 
              buttons: { 
               "OK": function() { 
                $(this).dialog("close"); 
               }, 
               "Cancel": function() { 
                $(this).dialog("close"); 
               } 
              } 
              }); 
     } 
    </script> 
</head> 
<body> 
    <div id="somediv"></div> 
    <a href="#" onclick="openDialog('SelectTeam.php?TeamIds=2,4,13');">Dialog</a> 
</body> 
    </html> 

子頁面 -

<?php 

$lstTeamId = array(); 

if (isset($_GET['TeamIds'])) 
{ 
$lstTeamId = explode(',', $_GET['TeamIds']); 
} 
?> 

<!DOCTYPE html> 
<html> 
<body> 
    <form id="frmSelectTeams"> 

     <table width="100%" border="1"> 
      <tr> 
       <th align="center"><input type="checkbox" disabled="disabled"/></th> 
       <th align="center">Team Name</th> 
      </tr> 

      <?php 
      for ($index = 1; $index < 21; $index++) 
      { 
       echo '<tr>'; 
       echo '<td align="center"><input type="checkbox" class="test" name="chk' . $index . '" '; if (in_array ($index, $lstTeamId)) { echo 'checked="checked"';} echo ' /></td>'; 
       echo '<td align="center">Team ' . $index . '</td>'; 
       echo "</tr>"; 
      } 
      ?> 

     </table> 
    </form> 
</body> 
</html> 
+0

你的複選框都應該是單選按鈕,如果你只想要一個選擇......?他們應該有與你想要選擇的值相同的值,即新的選擇網址? – Stefan 2012-03-30 09:59:55

回答

0

你就不能再次調用openDialog(URL),與新選擇的網址是什麼?

buttons: { 
    "OK":  function() 
       new_url = 'new_selection_url'; 
       openDialog(new_url); 
       }, 
    "Cancel": function() { 
       $(this).dialog("close"); 
      } 
} 

編輯:我不太確定您是否希望選擇顯示。新的選擇必須在對話框中嗎?在對話框外面?

更新:好的,看起來像你想要加載到#somediv。只需再次調用加載:

buttons: { 
    "OK":  function() 
       new_url = 'new_selection_url'; 
       $('#somediv').load(new_url); 
       }, 

更新:如果您只想選擇一個url,則必須改用單選按鈕。要獲得所有被選中的複選框的值,你可以嘗試這樣的事:

var urls = []; 
$('.test :checked').each(function() { 
    urls.push($(this).val()); 
}); 
new_url = urls[0]; 

如果更換單選按鈕的複選框,你可以嘗試這樣的事:

new_url = $('input[name=radioName]:checked', '#frmSelectTeams').val() 
相關問題