views:

39

answers:

1

I have a pop up window which lists images using a form and radio buttons.

When i click a radio button, the function is called which should pass back to the parent window.

I keep getting 'undefined' as the value which means to me that the variable hasn't been set.

How do i get around this error?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<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  A: 

Why not just send the radio button value directly to the function, rather than the full radio button reference:

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
   }
}

In action here.

Pat
exactly what i was trying to do....thanks
AdRock