Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Problem when using javascript

Reply
Thread Tools

Problem when using javascript

 
 
anthonybrough@googlemail.com
Guest
Posts: n/a
 
      12-09-2006
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="javascriptick_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>

 
Reply With Quote
 
 
 
 
Mike Brind
Guest
Posts: n/a
 
      12-09-2006

<> wrote in message
news: 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="javascriptick_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


 
Reply With Quote
 
 
 
 
anthonybrough@googlemail.com
Guest
Posts: n/a
 
      12-10-2006
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:

> <> wrote in message
> news: 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="javascriptick_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


 
Reply With Quote
 
Mike Brind
Guest
Posts: n/a
 
      12-11-2006

<> wrote in message
news: ps.com...

>
> Mike Brind wrote:
>
>> <> wrote in message
>> news: 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:
>> >


[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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript to Validate the Phone Number Field Using Javascript :-) Abhishek Javascript 5 08-07-2008 09:14 AM
dynamic javascript and html using javascript parez Javascript 0 09-11-2007 04:08 PM
using css in html embedded in xml rendered using xsl with javascript (phew) confused XML 3 05-25-2007 11:06 PM
Extract links from Javascript (not using Javascript)? chrisspencer02@yahoo.com Javascript 8 05-30-2006 08:46 AM
tricky javascript problem requires javascript guru ! Andy Javascript 2 03-04-2004 08:19 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57