2010-08-05 47 views
2

我有一個彈出式窗口,它使用窗體和單選按鈕列出圖像。從窗體輸入單選按鈕的javascript undefined錯誤

當我點擊一個單選按鈕時,函數被調用,應該返回到父窗口。

我不斷收到未定義的值,這意味着變量沒有被設置。

我該如何解決這個錯誤?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
<head> 
</head> 
<body> 
<script type="text/javascript"> 
<!-- Begin 
function sendValue (s){ 
var selvalue = s.value; 
//window.opener.document.getElementById('details').value = selvalue; 
//window.close(); 

alert(selvalue); 
} 
// End --> 
</script> 
<form name="selectform"> 

<?php 

    // Define the full path to your folder from root 

    $path = "../../images/news/"; 

    // Open the folder 
    $dir_handle = @opendir($path) or die("Unable to open $path"); 

    // Loop through the files 
    while ($file = readdir($dir_handle)) { 
     if($file == "." || $file == ".." || $file == "index.php") 
      continue; 
     $myfile = $file; 
     echo '<input type="radio" name="details" value="'.$myfile.'" onClick="sendValue(this.form.details);" />'.$file.'<br />'; 
    } 

    // Close 
    closedir($dir_handle); 
?> 
</form> 
</body> 
</html> 

回答

1

爲什麼不乾脆的單選按鈕值直接發送給函數,而不是完整的單選按鈕參考:

HTML

<input type="radio" name="details" value="1" onClick="sendValue(this.value);" /> 
<input type="radio" name="details" value="2" onClick="sendValue(this.value);" /> 

的Javascript

function sendValue(val){ 
    alert(val); 
    if(window.opener && !window.opener.closed) { 
     // do something with the parent window 
    } 
} 

action here

+0

正是我想要做的....謝謝 – AdRock 2010-08-05 18:54:30