news:1165699095.201469.142280@j44g2000cwa.googlegr oups.com...
Quote:
>I have an asp page that has a form to collect user data in a form.
when the user clicks submit the input is validated. If any fields are
not acceptable the user clicks on a button to go back to the original
form to correct the input. This all works fine until I try to
incorporate a javascript to display a popup calendar which posts the
selected date back to a field on the form. This script works fine in
itself, however if the page is submitted after this script has run and
other fields are not valid, then when I go back to the form ALL the
data entered is cleared. I am fairly new to asp and at a lost as to
what i am doing wrong.
>
I would appreciate any pointers as to how I can correct this.
>
My asp page is is follows:
>
<!-- #INCLUDE FILE="includes/Top.asp" --Handles database connects
<!-- #INCLUDE FILE="cal_inc.asp" --' contains the Javascript to
handle the popup window
>
<% If (0 = Request.ServerVariables("CONTENT_LENGTH")) Then %>
>
<FORM ACTION="<%=Request.ServerVariables("SCRIPT_NAME")% >" method= post
name = example_form><CENTER>
>
' VArious Input elements
<a href="javascript
:ShowDate('example_form','DATE');" >Pick Date</a'
hyperlink to javascript window to complete a field if required
>
' Validation of data input
>
<input type="button" value="Click here to make your changes"
onClick="history.go(-1) "' button to go back to original form if
invalid data found
>
The cal_inc.asp is :
<SCRIPT language="Javascript">
function ShowDate(date_form, date_field)
{
>
url='mc_calendar.asp?date_form=' + date_form + '&date_field=' +
date_field;
window.open(url,"_blank","height=200,width=370, resizable=yes");
>
}
</SCRIPT>
>
and the ='mc_calendar.asp page which it calls is :
>
<html>
<head>
<meta http-equiv="Content-Language" content="es-bo">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Pick a calendar date...</title>
<SCRIPT language="Javascript">
>
function change_cal()
{
var today = new Date();
month=document.cal_form.sel_month.options[document.cal_form.sel_month.options.selectedIndex].value;
year=document.cal_form.sel_year.options[document.cal_form.sel_year.options.selectedIndex].value;
month_dif=month-(today.getMonth()+1);
year_dif=year-today.getYear();
url='mc_calendar.asp?sel_month=' + month + '&sel_year=' + year +
'&month_dif=' + month_dif
+ '&year_dif=' + year_dif + '&date_form=<% =request("date_form") %>'
+ '&date_field=<% =request("date_field") %>';
window.location=url;
}
>
function pick_date(s_day, s_month, s_year)
{
>
if (window.opener && !window.opener.closed)
{
>
window.opener.document.<% =request("date_form") %>.<%
=request("date_field") %>.value =s_day + "/" + s_month + "/" + s_year;
}
>
window.close();
>
}
>
>
>
</SCRIPT>
</head>
>
<body link="#008000" vlink="#008000" alink="#FF0000" topmargin="0"
leftmargin="0" rightmargin="0" bottommargin="0">
<table border="0" cellpadding="0" style="border-collapse: collapse"
id="table3">
<tr>
<td>
<% if request("sel_month")<>"" then
sel_month=request("sel_month")
else
sel_month=month(now)
end if
if request("sel_year")<>"" then
sel_year=request("sel_year")
else
sel_year=year(now)
end if
if request("month_dif")<>"" then
month_dif=cint(request("month_dif"))
else
month_dif=0
end if
if request("year_dif")<>"" then
year_dif=cint(request("year_dif"))
else
year_dif=0
end if
>
new_now=DateAdd("m",month_dif,now)
new_now=DateAdd("yyyy",year_dif,new_now)
'response.write("new_now: " & new_now & "<br>")
first_week_day=WeekDay( new_now- ( day(new_now)-1 ) )
'response.write("first weekday: " & first_week_day & "<br>")
if first_week_day=1 then
date_cursor=-7
else
date_cursor=(first_week_day-1)*-1
end if
>
'response.write("date cursor: " & date_cursor & "<br>")
>
first_show_day=day(new_now-(day(new_now)-1)+date_cursor)
>
'response.write("first show day: " & first_show_day & "<br>")
>
%>
<table border="3" id="table4" cellspacing="1">
<form name="cal_form">
<tr>
<td colspan="7">
<div align="left">
<table border="0" cellpadding="0" style="border-collapse:
collapse" id="table5">
<tr>
<td>
<p align="left"><font size="1" face="Arial
Narrow">
<a href="mc_calendar.asp?date_form=<% =request("date_form")
%>&date_field=<% =request("date_field") %>">GO<br>
TODAY</a> </font></td>
<td>
<p align="right"><b><font face="Verdana" color="#000080">
<% response.write(MonthName(sel_month)) %>
<% response.write(sel_year) %>
</font></b></td>
<td><font face="Verdana">
<select size="1" name="sel_month" onchange="javascript
:
change_cal();">
<% for i=1 to 12 %>
<option
<% if i=cint(sel_month) then %>
selected
<% end if %>
value="<% =i %>"><% response.write(MonthName(i)) %></option>
<% next %>
</select></font></td>
<td><font face="Verdana">
<select size="1" name="sel_year" onchange="javascript
:
change_cal();">
<% for i=1900 to 2100 %>
<option
<% if i=cint(sel_year) then %>
selected
<% end if %>
value="<% =i %>"><% =i %>
</option>
<% next %>
</select></font></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td align="center"><b><font face="Verdana" size="1"
color="#000080">Sunday</font></b></td>
<td align="center"><b><font face="Verdana" size="1"
color="#000080">Monday</font></b></td>
<td align="center"><b><font face="Verdana" size="1"
color="#000080">Tuesday</font></b></td>
<td align="center"><b><font face="Verdana" size="1"
color="#000080">
Wednesday</font></b></td>
<td align="center"><b><font face="Verdana" size="1"
color="#000080">Thursday</font></b></td>
<td align="center"><b><font face="Verdana" size="1"
color="#000080">Friday</font></b></td>
<td align="center"><b><font face="Verdana" size="1"
color="#000080">Saturday</font></b></td>
</tr>
<% for i=1 to 42 %>
<% if WeekDay(new_now-(day(new_now)-1)+date_cursor)=1 then
if i>1 then %>
</tr>
<% end if %>
<tr>
<% end if %>
<td>
<% if (date_cursor>=0 and date_cursor<=2) or (date_cursor>=3 and
date_cursor<=30 and day(new_now-(day(new_now)-1)+date_cursor)>3) then
%>
<p align="center">
<b>
<a href="javascript
:pick_date('<%
=day(new_now-(day(new_now)-1)+date_cursor) %>','<% =sel_month %>','<%
=sel_year %>');">
<% if month(now)=month(new_now) and
day(new_now)=day(new_now-(day(new_now)-1)+date_cursor) then
>
%>
<font face="Verdana" size="2" color="#FF0000">
<% else %>
<font face="Verdana" size="2" color="#008000">
<% end if %>
>
<% response.write( day(new_now-(day(new_now)-1)+date_cursor)
) %>
</font>
</a></b>
</p>
<% elseif date_cursor<0 or date_cursor>=28 then %>
<font face="Verdana" size="2" color="#C0C0C0">
<p align="center">
<b>
<% response.write( day(new_now-(day(new_now)-1)+date_cursor) )
%></b>
</p>
</font>
<% end if %>
</td>
<% date_cursor=date_cursor+1 %>
<% next %>
</form>
</table>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</body>
>
</html>
>
circumstances. It may work in the version of browser you have on your
machine, with your setup, but it might not in mine.
You would be better off getting the form to post to itself. If it
Request.QueryString. You are forcing a search of each collection in turn
until the correct one is found.