473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem when using javascript

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
3 2073

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

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site....
1
by: Julius Mong | last post by:
Dear all, according to the ASV3 manual known problem section, to make an <a> execute some Javascript onclick: ...
5
by: Tony Strazzeri | last post by:
Hi all, I a fairly new to html and Javascripting. I have been trying to write some code to hide my email address from spam harvesters. I copied the code from various web examples and modified...
9
by: fochie | last post by:
Greetings, I'm having a problem when I try to GET a file from my server via xmlhttp when using Mozilla. With IE I can get any type of file fine, get/display headers fine, etc. With Mozilla,...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
0
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I...
3
by: Microsoft Newsgroups | last post by:
Hi all, I'm having an interesting problem with my IE Webcontrols. I'm using the toolbar and when I test it in my browser using "http://localhost/mysite", it works fine. Incidentally, I have...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
4
by: Miguel Dias Moura | last post by:
Hello, I am having problems in accessing controls in my Asp.Net 2.0 pages. I know Asp.Net 2.0 generates a ClientId. In a Javascript function I tried to hide a panel as follows: function...
4
by: r_ahimsa_m | last post by:
Hello, I am learning WWW technologies in Linux. I created index.html file which I can browse with Firefox/Konqueror using URL localhost/~robert/rozgloszenia/index.html. The page looks fine but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.