when i click on the iframe date (calendar.asp), it should update the parent (test2.asp) date fields.

However, whenever the iframe page is refreshed by selecting other month/year, it seems to lost its parent and can't return the selected date to its parent anymore.

how do i prevent the iframe from losing its parent after its been refreshed.

is there anyway javascript can solve this or this the limitation of javascript?

Test.asp codes
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body>
<form method="POST" id="FORM1" name="FORM1" action="aaa">
Selected Date:<input type="text" name="date1" id="date1" value="" >
<br>
<iframe
src ="calendar2.asp?dateForm=FORM1&dateBox=date1" width="300" height="300">
</iframe>
</form>
</body>
</html>

calendar.asp code
Calendar2.asp - this is the iframe page.
-----------------------
<html>
<head>
<title>Select Date</title>

<style type="text/css">
<!--

.Calbox {
border: 0px solid #a0a0a0;
width: 226px;
height: 210px;
padding: 2px 2px 2px 2px;
}


.cal-head-box {
width: 220px;
border: none;
height: 25px;
padding: 2px 3px 2px 3px;
background: url('cal-img/cal-bg.gif');
background-repeat: repeat-x;
background-position: top ;
text-align: left;
}

.cal-body-box {
width: 220px;
border: none;
height: 155px;
text-align: left;
}

.cal-footer-box {
width: 220px;
border: none;
height: 20px;
background-color: #f0f0f0;
padding: 2px 3px 2px 3px;
text-align: center;
font-family: Arial, Verdana, 'MS Sans Serif', 'Lucida Grande', Sans-Serif;
font-size: 8pt;
}


.cal-head2 {

padding: 1px 3px 1px 3px;

}

.cal-select-box
{
BORDER: #FFFFFF 1px solid;
BACKGROUND-COLOR: #FAF5F5;
FONT-WEIGHT: bold;
color: #000000;
font-family: Arial, Verdana, 'MS Sans Serif', 'Lucida Grande', Sans-Serif;
font-size: 8pt;

}

.cal-text
{

FONT-WEIGHT: normal;
color: #000000;
font-family: Arial, 'MS Sans Serif', 'Lucida Grande', Sans-Serif;
font-size: 8pt;
line-height: 160%;
text-align: center;
align: center;
padding-top: 4px;

}

.day {
font-family: Verdana, Arial, 'MS Sans Serif', 'Lucida Grande', Sans-Serif;
font-size: 8pt;
color:black;
text-decoration: none;

}

.red {
font-family: Verdana, Arial, 'MS Sans Serif', 'Lucida Grande', Sans-Serif;
font-size: 8pt;
color:red;
font-weight: bold;
text-decoration: none;
}



a.day:hover
{
font-weight: bold;
border: 2px solid #804040;
padding: 1px;
}

a.red:hover
{
font-weight: bold;
border: 2px solid #804040;
padding: 1px;
}

body
{
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
text-align: left;
}
-->
</style>
</head>

<%
dateForm = request.querystring("dateForm")
dateBox = request.querystring("dateBox")

%>
<script type="text/javascript">
<!--
var parentHREF ;
var dateForm;
var dateBox;

function giveDate3(str){
alert(str);
}

function giveDate(str){
dateForm = "<%=dateForm%>";
dateBox = "<%=dateBox%>";

parent.document.getElementById([dateBox]).value = str;

}

function yearChange(){
monthVar = <%=monthVar%>
yearVar = document.all.year.value
window.location="calendar.asp?dateForm=<%=dateForm %>&dateBox=<%=dateBox%>&monthVar="+(monthVar)+"&ye ar="+(yearVar)
}

function monthChange(){

monthVar = document.all.month.value
window.location="calendar.asp?dateForm=<%=dateForm %>&dateBox=<%=dateBox%>&monthVar="+(monthVar)
}

function fireChangeEventOnParent(newValue){
if (typeof(parent.IframContentChangedEvent)=='functio n') {
parent.IframContentChangedEvent(newValue);
}
else {
alert(typeof(parent.IframContentChangedEvent));
}
}

-->
</script>

<body bgcolor="" leftmargin="0" marginwidth="0" marginheight="0">
<div class="Calbox">

<%
dateDay = Day(now)
if dateDay <10 then
dateDay = "0" & dateDay
end if

dateMonth=Month(now)
if dateMonth <10 then
dateMonth = "0"&dateMonth
end if

dateYear = Right(Year(now),2)
yearNow = Year(now)

dateNow = dateDay&"/"&dateMonth&"/"&yearNow
'find the day today
dayToday = WeekDay(dateNow)
dayToday = WeekDayName(dayToday)

if request.querystring("monthVar") = "" then
session("yearVar") = yearNow
monthVar = dateMonth
else

monthVar = CLng(request.QueryString("monthVar"))
yearVar = yearVar
if monthVar > 12 then
monthVar = 1
session("yearVar") = CLng(session("yearVar") +1)
end if
if monthVar < 1 then
monthVar = 12
session("yearVar") = CLng(session("yearVar") -1)
end if
end if

if request.QueryString("year") <> "" then
session("yearVar") = request.QueryString("year")
else
session("yearVar") = year(date())
end if

yearVar = session("yearVar")

function dateNew(m,d)
dateDayNew = d
if dateDayNew <10 then dateDayNew = "0"&dateDayNew
dateMonthNew=m
if dateMonthNew <10 then dateMonthNew = "0"&dateMonthNew
'dateYearNew = Right(Year(now),2)
yearNowNew = yearVar
dateNew = dateDayNew&"/"&dateMonthNew&"/"&yearNowNew

end function
%>

<div class="cal-head-box">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr >
<td width="20" class="cal-head2" >
<a href ="calendar.asp?dateForm=<%=dateForm%>&dateBox=<%=d ateBox%>&monthVar=<%=monthVar -1%>">
<img src="cal-img/cal-back.gif" width="18" height="16" alt="" border="0">
</a>
</td>
<td width="20" class="cal-head2" >
<a href ="calendar.asp?dateForm=<%=dateForm%>&dateBox=<%=d ateBox%>&monthVar=<%=monthVar +1%>">
<img src="cal-img/cal-next.gif" width="18" height="16" alt="" border="0">
</a>
</td>
<td width="80" class="cal-head2">
<select class="cal-select-box" name="month" onchange="monthChange()">
<option value="<%=monthVar%>" selected><%=monthname(monthVar)%></option>
<option value="01">January</option>
<option value="02">Febuary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</td>
<td width="60" class="cal-head2">
<select class="cal-select-box" name="year" onchange="yearChange()">
<option value="<%=yearVar%>" selected><%=yearVar%></option>
<option value="2000">2000</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
</select>
</td>
<!--
<td width="20" class="cal-head2" >
<a href="javascript: window.close();">
<img src="cal-img/cal-close.gif" width="15" height="13" alt="" border="0">
</a>
</td>
-->
</tr>
</table>
</div>
<div class="cal-body-box">
<table width="220" border="0" cellpadding="0" cellspacing="0" >
<tr align="center">
<td width="30" >
<p class="cal-text" ><b>Sun</b></p>
</td>
<td width="30" >
<p class="cal-text" ><b>Mon</b></p>
</td>
<td width="30" >
<p class="cal-text" ><b>Tue</b></p>
</td>
<td width="30" >
<p class="cal-text" ><b>Wed</b></p>
</td>
<td width="30" >
<p class="cal-text" ><b>Thu</b></p>
</td>
<td width="30" >
<p class="cal-text" ><b>Fri</b></p>
</td>
<td width="30" >
<p class="cal-text" ><b>Sat</b></p>
</td>
</tr>
<tr>
<%

startPos = WeekDay(1&"/"&monthVar&"/"&yearVar)
col = startPos-1
for t = 1 to col
%>
<td class ="cal-text">&nbsp; </td>
<%
next

for x = monthVar to monthVar
dateDays = Day( DateSerial( yearVar, x+1, 0 ) )
for n = 1 to dateDays
col=col+1
newdate= dateNew(x,n)
newTodayNum = WeekDay(newdate)
newToday = WeekDayName(newTodayNum)
dateDay = datepart("d",newdate)
if dateDay < 10 then
dateDay = "0" & dateDay
end if

if dateNow = newdate then
font ="red"
else
font = "day"
end if %>
<td class="cal-text">
<%if newTodayNum = 1 then %>
<span class="<%=font%>" ><strike><%=dateDay%></strike> </span>
<%else%>
<a class="<%=font%>" href="#" onclick="javascript:giveDate('<%=newdate%>');">
<%=dateDay%>
</a>
<%end if%>
</td>
<%
if col mod 7 = 0 and n <> dateDays then
%></tr><tr> <%
end if

next
if col mod 7 <> 0 then
while col mod 7 <> 0
response.write(" <td class = 'cal-text'> </td>"&vbcrlf)
col = col+1
wend
response.write(" </tr>"&vbcrlf)
end if
next
%>
</table>
</div>
<div class="cal-footer-box">Today is <%=FormatDateTime(Date(),1)%>
</div>
</div>
</body>
</html>