By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,534 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,534 IT Pros & Developers. It's quick & easy.

Problem when using javascript

P: n/a
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">&nbsp;&nbsp;
<a href="mc_calendar.asp?date_form=<% =request("date_form")
%>&date_field=<% =request("date_field") %>">GO<br>
TODAY</a>&nbsp;&nbsp;&nbsp;&nbsp; </font></td>
<td>
<p align="right"><b><font face="Verdana" color="#000080">
&nbsp;<% response.write(MonthName(sel_month)) %>&nbsp;
<% response.write(sel_year) %>&nbsp;&nbsp;
</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>

Dec 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

<an***********@googlemail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
>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">&nbsp;&nbsp;
<a href="mc_calendar.asp?date_form=<% =request("date_form")
%>&date_field=<% =request("date_field") %>">GO<br>
TODAY</a>&nbsp;&nbsp;&nbsp;&nbsp; </font></td>
<td>
<p align="right"><b><font face="Verdana" color="#000080">
&nbsp;<% response.write(MonthName(sel_month)) %>&nbsp;
<% response.write(sel_year) %>&nbsp;&nbsp;
</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>
You can't rely on history.go(-1) to retain values in forms under any
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
validates, process the values, if not, show the form again with the posted
values:

<%
Sub showform
%>
<form name="myform" method="post" action="">
Enter name: <input type="text" name="thename"
value="<%=Request.Form("thename")%>"><br>
<input type="submit" name="Action" value="Submit">
</form>
<%
End Sub

If Request.Form("Action") = "Submit" Then 'user has submitted
'validate
If pass then
'Process values
Else 'if failed
showForm
End If
Else 'user has NOT submitted
showform
End If
%>

By the way, you should never refer to the request collection without
qualifying which one you are dealing with - Request.Form or
Request.QueryString. You are forcing a search of each collection in turn
until the correct one is found.

--
Mike Brind
Dec 9 '06 #2

P: n/a
Hi Mike

Thanks for the reply.

I have taken your points on board and redesigned the page. It all works
well with the exception of Checkboxes. I have tried searhing here but
cannot seem to find a way to make the the form redisplay and show the
checked state of the checkbox.

In my original form I have the following:

<input type="checkbox" name="C1" value="ON" tabindex="20">

when the form is posted I can get the value of the checkbox using:

strC1 = request.form("C1") which returns "ON" as expected.

however I cannot find a way to set the value back to the posted form.

I would be grateful of any assistance.

Regards
Tony

Mike Brind wrote:
<an***********@googlemail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
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">&nbsp;&nbsp;
<a href="mc_calendar.asp?date_form=<% =request("date_form")
%>&date_field=<% =request("date_field") %>">GO<br>
TODAY</a>&nbsp;&nbsp;&nbsp;&nbsp; </font></td>
<td>
<p align="right"><b><font face="Verdana" color="#000080">
&nbsp;<% response.write(MonthName(sel_month)) %>&nbsp;
<% response.write(sel_year) %>&nbsp;&nbsp;
</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>

You can't rely on history.go(-1) to retain values in forms under any
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
validates, process the values, if not, show the form again with the posted
values:

<%
Sub showform
%>
<form name="myform" method="post" action="">
Enter name: <input type="text" name="thename"
value="<%=Request.Form("thename")%>"><br>
<input type="submit" name="Action" value="Submit">
</form>
<%
End Sub

If Request.Form("Action") = "Submit" Then 'user has submitted
'validate
If pass then
'Process values
Else 'if failed
showForm
End If
Else 'user has NOT submitted
showform
End If
%>

By the way, you should never refer to the request collection without
qualifying which one you are dealing with - Request.Form or
Request.QueryString. You are forcing a search of each collection in turn
until the correct one is found.

--
Mike Brind
Dec 10 '06 #3

P: n/a

<an***********@googlemail.comwrote in message
news:11*********************@79g2000cws.googlegrou ps.com...
>
Mike Brind wrote:
><an***********@googlemail.comwrote in message
news:11**********************@j44g2000cwa.googleg roups.com...
>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:
[snipped]
>>
You can't rely on history.go(-1) to retain values in forms under any
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
validates, process the values, if not, show the form again with the
posted
values:

<%
Sub showform
%>
<form name="myform" method="post" action="">
Enter name: <input type="text" name="thename"
value="<%=Request.Form("thename")%>"><br>
<input type="submit" name="Action" value="Submit">
</form>
<%
End Sub

If Request.Form("Action") = "Submit" Then 'user has submitted
'validate
If pass then
'Process values
Else 'if failed
showForm
End If
Else 'user has NOT submitted
showform
End If
%>

By the way, you should never refer to the request collection without
qualifying which one you are dealing with - Request.Form or
Request.QueryString. You are forcing a search of each collection in turn
until the correct one is found.

--
Mike Brind
Hi Mike

Thanks for the reply.

I have taken your points on board and redesigned the page. It all works
well with the exception of Checkboxes. I have tried searhing here but
cannot seem to find a way to make the the form redisplay and show the
checked state of the checkbox.

In my original form I have the following:

<input type="checkbox" name="C1" value="ON" tabindex="20">
when the form is posted I can get the value of the checkbox using:
strC1 = request.form("C1") which returns "ON" as expected.
however I cannot find a way to set the value back to the posted form.
I would be grateful of any assistance.
<input type="checkbox" name="C1" value="ON" tabindex="20" <% if
Request.Form("C1")="ON" Then Response.Write " checked" %

--
Mike Brind
Dec 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.