Problem when using javascript

Problem when using javascript

am 09.12.2006 22:18:15 von anthonybrough

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:

Handles database connects
' contains the Javascript to
handle the popup window

<% If (0 = Request.ServerVariables("CONTENT_LENGTH")) Then %>

" method= post
name = example_form>


' VArious Input elements
'
hyperlink to javascript window to complete a field if required

' Validation of data input

onClick="history.go(-1) "> ' button to go back to original form if
invalid data found

The cal_inc.asp is :


and the ='mc_calendar.asp page which it calls is :





Pick a calendar date...



leftmargin="0" rightmargin="0" bottommargin="0">
id="table3">







<% 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 & "
")
first_week_day=WeekDay( new_now- ( day(new_now)-1 ) )
'response.write("first weekday: " & first_week_day & "
")
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 & "
")

first_show_day=day(new_now-(day(new_now)-1)+date_cursor)

'response.write("first show day: " & first_show_day & "
")

%>














<% for i=1 to 42 %>
<% if WeekDay(new_now-(day(new_now)-1)+date_cursor)=1 then
if i>1 then %>

<% end if %>

<% end if %>

<% date_cursor=date_cursor+1 %>
<% next %>











  
%>&date_field=<% =request("date_field") %>">GO

TODAY
    



 <% response.write(MonthName(sel_month)) %> 
<% response.write(sel_year) %>  





color="#000080">Sunday color="#000080">Monday color="#000080">Tuesday color="#000080">
Wednesday
color="#000080">Thursday color="#000080">Friday color="#000080">Saturday

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




<% if month(now)=month(new_now) and
day(new_now)=day(new_now-(day(new_now)-1)+date_cursor) then

%>

<% else %>

<% end if %>

<% response.write( day(new_now-(day(new_now)-1)+date_cursor)
) %>



<% elseif date_cursor<0 or date_cursor>=28 then %>



<% response.write( day(new_now-(day(new_now)-1)+date_cursor) )
%>



<% end if %>





Re: Problem when using javascript

am 09.12.2006 23:27:31 von Mike Brind

wrote in message
news:1165699095.201469.142280@j44g2000cwa.googlegroups.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:
>
> Handles database connects
> ' contains the Javascript to
> handle the popup window
>
> <% If (0 = Request.ServerVariables("CONTENT_LENGTH")) Then %>
>
>

" method= post
> name = example_form>

>
> ' VArious Input elements
> '
> hyperlink to javascript window to complete a field if required
>
> ' Validation of data input
>
> > onClick="history.go(-1) "> ' button to go back to original form if
> invalid data found
>
> The cal_inc.asp is :
>
>
> and the ='mc_calendar.asp page which it calls is :
>
>
>
>
>
> Pick a calendar date...
>
>
>
> > leftmargin="0" rightmargin="0" bottommargin="0">
> > id="table3">
>
>
>
>
>
>
>

> <% 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 & "
")
> first_week_day=WeekDay( new_now- ( day(new_now)-1 ) )
> 'response.write("first weekday: " & first_week_day & "
")
> 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 & "
")
>
> first_show_day=day(new_now-(day(new_now)-1)+date_cursor)
>
> 'response.write("first show day: " & first_show_day & "
")
>
> %>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> <% for i=1 to 42 %>
> <% if WeekDay(new_now-(day(new_now)-1)+date_cursor)=1 then
> if i>1 then %>
>
> <% end if %>
>
> <% end if %>
>
> <% date_cursor=date_cursor+1 %>
> <% next %>
>
>

>

>
>
>
>
>
>
>
>

>

  
> > %>&date_field=<% =request("date_field") %>">GO

> TODAY
    


>


>  <% response.write(MonthName(sel_month)) %> 
> <% response.write(sel_year) %>  
>


>

>

>

>
> color="#000080">Sunday > color="#000080">Monday > color="#000080">Tuesday > color="#000080">
> Wednesday
> color="#000080">Thursday > color="#000080">Friday > color="#000080">Saturday

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


>
>
> <% if month(now)=month(new_now) and
> day(new_now)=day(new_now-(day(new_now)-1)+date_cursor) then
>
> %>
>
> <% else %>
>
> <% end if %>
>
> <% response.write( day(new_now-(day(new_now)-1)+date_cursor)
> ) %>
>

>

>


> <% elseif date_cursor<0 or date_cursor>=28 then %>
>
>


>
> <% response.write( day(new_now-(day(new_now)-1)+date_cursor) )
> %>

>


>

> <% end if %>
>

>

>

>
>
>
>

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

Enter name: value="<%=Request.Form("thename")%>">



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

Re: Problem when using javascript

am 10.12.2006 22:56:50 von anthonybrough

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:



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:1165699095.201469.142280@j44g2000cwa.googlegroups.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:
> >
> > Handles database connects
> > ' contains the Javascript to
> > handle the popup window
> >
> > <% If (0 = Request.ServerVariables("CONTENT_LENGTH")) Then %>
> >
> >

" method= post
> > name = example_form>

> >
> > ' VArious Input elements
> > '
> > hyperlink to javascript window to complete a field if required
> >
> > ' Validation of data input
> >
> > > > onClick="history.go(-1) "> ' button to go back to original form if
> > invalid data found
> >
> > The cal_inc.asp is :
> >
> >
> > and the ='mc_calendar.asp page which it calls is :
> >
> >
> >
> >
> >
> > Pick a calendar date...
> >
> >
> >
> > > > leftmargin="0" rightmargin="0" bottommargin="0">
> > > > id="table3">
> >
> >
> >
> >
> >
> >
> >

> > <% 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 & "
")
> > first_week_day=WeekDay( new_now- ( day(new_now)-1 ) )
> > 'response.write("first weekday: " & first_week_day & "
")
> > 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 & "
")
> >
> > first_show_day=day(new_now-(day(new_now)-1)+date_cursor)
> >
> > 'response.write("first show day: " & first_show_day & "
")
> >
> > %>
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > <% for i=1 to 42 %>
> > <% if WeekDay(new_now-(day(new_now)-1)+date_cursor)=1 then
> > if i>1 then %>
> >
> > <% end if %>
> >
> > <% end if %>
> >
> > <% date_cursor=date_cursor+1 %>
> > <% next %>
> >
> >

> >

> >
> >
> >
> >
> >
> >
> >
> >

> >

  
> > > > %>&date_field=<% =request("date_field") %>">GO

> > TODAY
    


> >


> >  <% response.write(MonthName(sel_month)) %> 
> > <% response.write(sel_year) %>  
> >


> >

> >

> >

> >
> > color="#000080">Sunday > > color="#000080">Monday > > color="#000080">Tuesday > > color="#000080">
> > Wednesday
> > color="#000080">Thursday > > color="#000080">Friday > > color="#000080">Saturday

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


> >
> >
> > <% if month(now)=month(new_now) and
> > day(new_now)=day(new_now-(day(new_now)-1)+date_cursor) then
> >
> > %>
> >
> > <% else %>
> >
> > <% end if %>
> >
> > <% response.write( day(new_now-(day(new_now)-1)+date_cursor)
> > ) %>
> >

> >

> >


> > <% elseif date_cursor<0 or date_cursor>=28 then %>
> >
> >


> >
> > <% response.write( day(new_now-(day(new_now)-1)+date_cursor) )
> > %>

> >


> >

> > <% end if %>
> >

> >

> >

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

> Enter name: > value="<%=Request.Form("thename")%>">

>
>

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

Re: Problem when using javascript

am 11.12.2006 09:14:46 von Mike Brind

wrote in message
news:1165787810.716947.72030@79g2000cws.googlegroups.com...

>
> Mike Brind wrote:
>
>> wrote in message
>> news:1165699095.201469.142280@j44g2000cwa.googlegroups.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
>> %>
>>


>> Enter name: >> value="<%=Request.Form("thename")%>">

>>
>>

>> <%
>> 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:
>
>
> 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.
>

Request.Form("C1")="ON" Then Response.Write " checked" %> >

--
Mike Brind