I have two html files as shown below.

PHP Code:
ran.html
<html>
<
head>
<
title>Test</title>
</
head>
<
body>
<
div id="divx"></div>
<
input type="button" onclick="first();" value="Create">
<
input type="button" value="ShowVal" onclick="second();">
<
script>
second=function(){
        
alert("WINDOW : "+window.iframex.val+"---------FRAMES : "+frames['iframex'].val);
        var 
y=document.getElementById('divx').innerHTML="";
}

first=function(){
        
document.getElementById('divx').innerHTML='<iframe src="ran1.html" name="iframex"></iframe>';
}
</script>
</body>
</html> 
PHP Code:
ran1.html

<html>
<
head>
<
script>
var 
val="Value from ran1.html";
</script>
<style>
</style>
</head>
<body>
</body>
</html> 
In ran.html I have two buttons(Create & ShowVal). When I click on Create button, I create a iframe and when ShowVal is clicked I alert a javascript varaible which is in the created iframe and then remove the iframe.
This works fine for the first time. But for the second time the javascript variable shows undefined.

Can anyone help me to resolve this issue.

Naveen. V