If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > session variable update onChange

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-25-05, 10:43
care99bare care99bare is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
session variable update onChange

In my ASP page, I am trying to update a session variable onChange. The idea is, if the text in the box is changed and the page is navagated away from, when the page returns, the CHANGED value should be displayed. Here is the code i use for the textbox:

<textarea name="finding" rows=4 cols="50" onChange="session('finding')=this"><%response.writ e session("finding")%></textarea>

The session variables are populated elsewhere, but this SHOULD update that variable so that if the page is updated, returned to, etc., the value that the user entered should be displayed. However, when the page is reloaded, etc., the originial session variable remains. Any advice?
Reply With Quote
  #2 (permalink)  
Old 02-25-05, 11:01
DMWCincy DMWCincy is offline
Registered User
 
Join Date: May 2004
Posts: 125
Part of the problem is where you are trying to set the values. Session values work on the server side, not client side. The only way to store that value in a session variable would be to post back to the server with the data and set the value on the server side code.

DMW
Reply With Quote
  #3 (permalink)  
Old 02-25-05, 11:40
care99bare care99bare is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
Yeah, I forgot about that whole server/client side thing. I thought i had an easy fix to my larger problem. Ok, so how do i do that? I would have to submit the form in order to do that, right? If so, that's the problem i was having before that i coudn't get to work.

I was trying originally to submit the form if a certain link was clicked. here's the code i tried which doesn't seem to submit the form values:

<a href="http...self?link1clicked=1" onClick="document.update.submit()">Click here</a>

This statement was embedded in the <form>. When the form is submitted (concievably when this link is clicked or when the submit button is clicked), it returns to itself and this particular link returns a url which lets the form know that this link was clicked, and it has the code to update session variables with whatever values the form had at the time of submitting (ie changes), then redirect to the location selected. I thought updating onChange might be a way around this method, which i can't seem to get to work either.
Reply With Quote
  #4 (permalink)  
Old 02-25-05, 12:26
DMWCincy DMWCincy is offline
Registered User
 
Join Date: May 2004
Posts: 125
Quote:
Originally Posted by care99bare

<a href="http...self?link1clicked=1" onClick="document.update.submit()">Click here</a>
Try this. It should work under IE but I'm not sure how Firefox or any other browser will like it. So test it out on various browsers:


<a href="Javascript: FunctionCall();">Click here</a>

Then you can have a function call that can take care of doing the submit logic.

HTH
DMW
Reply With Quote
  #5 (permalink)  
Old 02-25-05, 13:14
care99bare care99bare is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
sounds good, but what would the jscript look like? I've never written in java (believe it or not), so i am lost on that point. thanks for your help. i won't be able to try it until Monday, but please don't forget to look for further questions from me.
Reply With Quote
  #6 (permalink)  
Old 02-25-05, 13:17
DMWCincy DMWCincy is offline
Registered User
 
Join Date: May 2004
Posts: 125
Java and javascript are two different things. A great place to check out for different web languagues is:

http://www.w3schools.com

Check this site out. I bet it will answer a bit of your questions for you.

Good luck!
DMW
Reply With Quote
  #7 (permalink)  
Old 02-28-05, 13:53
care99bare care99bare is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
The W3Schools site helps a little - just in understanding what Javascript is. but i'm still completely clueless about how to work this function. A javascript function won't work to put values into session variables, will it? If so, i'm at a complete loss as to how to do that. If not, I would have to submit the form before i could update the session values, so if i write a javascript function that basically does the "document.update.submit()" and then in the page still include the logic to update the session variables with the form values, how does adding the javascript function solve anything? Why can't I just use the onClick function? Am i completely lost?
Reply With Quote
  #8 (permalink)  
Old 02-28-05, 17:27
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
The server is the only place the session update/change can happen.

It's possible that a better idea, rather then changing the session value is to store the values in a cookie instead. Cookies can be access both in clientside script and serverside script so you wouldn't have the issues that you are currently facing.
Reply With Quote
  #9 (permalink)  
Old 03-01-05, 14:11
care99bare care99bare is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
I've re-written my session variables as cookies (thanks for that, BTW!), and that seems to be ok. Now the problem is my submit statement. Because the submit BUTTON does a different action, the submit which should update the cookie values is in an <a href> statement with an onClick command. The statement is:

<a href="http.../thispage.asp?submitreport=1" onClick="document.update.submit()">

Through the submitreport=1, the cookies are updated with the appropriate information, and the page is redirected elsewhere. The problem is, the information is not submitted! I have several text boxes and two selects which contain data on page load that can be changed if the user wishes, but the information in those boxes/selects is not passed to the page when the <a href> is clicked. What am i doing wrong?
Reply With Quote
  #10 (permalink)  
Old 03-01-05, 17:02
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
Hard to say exactly what is going wrong without seeing the rest of the page. It could be your submit is not nested int eh same form as your information or that during your submit action you have missed soimething to do with setting the value.

If you post the whole page we will have a look and help if we can.
Reply With Quote
  #11 (permalink)  
Old 03-04-05, 09:43
care99bare care99bare is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
the submit is within the form tags, and the information isn't even being passed into the function that saves the values, so it's somewhere in the submit function (i've determined). Here's the necessary part of the code:

<!--create cookies for update page -->
<%
Response.Cookies("update")("lid") = ""
Response.Cookies("update")("rinfo") = ""
Response.Cookies("update")("finding") = ""
Response.Cookies("update")("comment") = ""
Response.Cookies("update")("recommendation") = ""
Response.Cookies("update")("action") = ""
Response.Cookies("update")("dateofaction") = ""
Response.Cookies("update")("leadoffice") = ""
Response.Cookies("update")("cinfo") = ""
Response.Cookies("update").Expires = DATE + 1
%>
<html><head></head><body>

<%
'If submit report or correction were clicked
If request.querystring("submitreport")=1 or request.querystring("submitcorrection")=1 then
response.write "submit report/correction set"
If request.form("lid") = "" then
'don't set lid
response.write "no lid passed"
Else
response.cookies("update")("lid") = request.form("lid")
End if
response.cookies("update")("rinfo") = request.form("rinfo")
response.cookies("update")("finding") = request.form("finding")
response.cookies("update")("comment") = request.form("comment")
response.cookies("update")("recommendation") = request.form("recommendation")
response.cookies("update")("action") = request.form("action")
response.cookies("update")("dateofaction") = request.form("dateofaction")
response.cookies("update")("leadoffice") = request.form("leadoffice")
response.cookies("update")("cinfo") = request.form("cinfo")
response.write request.form("lid")
response.write request.form("finding")
response.write "form elements apparent"
response.write request.cookies("update")("lid")
response.write request.cookies("update")("finding")
response.write "cookies written"

'redirect to appropriate add page
If request.querystring("submitreport") =1 then
response.redirect("http://addreport.asp")
response.write "Submit report clicked"
window.stop()
ElseIf request.querystring("submitcorrection") =1 then
response.redirect("http://addcorrection.asp")
window.stop()
Else
'something went wrong
response.write "Error in page"
End if

'If no values were entered to submit
ElseIf request.form("submission")= "" then
submission = 0

'If values were entered to submit
Else

'Get all values
lid = request.form("lid")
rinfo = request.form("rinfo")
finding = request.form("finding")
finding = Replace(finding, "'", "''")
comment = request.form("comment")
comment = Replace(comment, "'", "''")
recommendation = request.form("recommendation")
recommendation = Replace(recommendation, "'", "''")
action = request.form("action")
action = Replace(action, "'", "''")
dateofaction = request.form("dateofaction")
leadoffice = request.form("leadoffice")
leadoffice = Replace(leadoffice, "'", "''")
cinfo = request.form("cinfo")

'Check to make sure that rtitle and
'something in finding have been entered
If rinfo="" then
response.write "<font color=red>You must choose a report.</font>"
ElseIf finding="" then
response.write "<font color=red>You must enter a finding.</font>"
Else
'Otherwise, add to database
'First, open database

'Next create the query
statement = "UPDATE lesson set rinfo='" & rinfo & "', finding='" & finding & "', comment='" & comment & "', recommendation='" & recommendation & "', action='" & action & "', date='" & dateofaction & "', lead='" & leadoffice & "', cinfo='" & cinfo & "' WHERE lid='" & lid & "'"

'perform the queries
Set RS = oConn.execute(statement)
If err.number>0 or oConn.errors.count>0 then
response.write "<font color=red>Errors occured. Information not stored in database."
response.write "<a href='http://addlesson.asp'>Please try again.</a>"
End if

'Close database connection
oConn.Close
set oConn = Nothing

'Now that update has been done, delete cookie
Response.cookies("update").Expires = Date()-1

'Pass lid back to update page

%>
<input type="hidden" name="lid" value=lid>
<%
End if

End if
%>

Directions for updating lessons in the database: <br /><br />

<%
'if lid isn't set
If request.cookies("update")("lid") = "" then
'Get lid from previous page
lid = request.querystring("lid")
response.cookies("update")("lid") = lid
End if
%>

<form name="update" action="http://updatelessoncookies.asp?lid=<%response.write request.cookies("update")("lid")%>" method="POST">
<table>
<tr>
<th colspan=3>Please enter the following information:</th>
</tr>
<tr>
<td>Report:</td>
<td> <select id="rinfo" size="1" name="rinfo" >
<option value="">Select One</option>
<option value="">-------------</option>

<%
'Get info from database report
'First, open database

'Get all info pertaining to LID
'if rinfo not set
If request.cookies("update")("rinfo") = "" then
info = RS("rinfo")
response.cookies("update")("rinfo") = info
End if

'format option output
do while not TS.EOF
rnumber = TS("rnumber")
response.write "<option value='" & rnumber & "'"
If request.cookies("update")("rinfo")=rnumber then
response.write " selected"
End if
response.write ">" & rnumber & "</option>"
TS.MoveNext
Loop
%></select></td>
<td>
<h5>Need to add a report to this list?
<a href="http://updatelessoncookies.asp?submitreport=1" onClick="document.update.submit()">
Click here</a></td>
</tr>

<%
'if this is the first time in update
if request.cookies("update")("finding") = "" then

'set up cookie values
response.cookies("update")("finding") = RS("finding")
response.cookies("update")("comment") = RS("comment")
response.cookies("update")("recommendation") = RS("recommendation")
response.cookies("update")("action") = RS("action")
response.cookies("update")("dateofaction") = RS("date")
response.cookies("update")("leadoffice") = RS("lead")
response.cookies("update")("cinfo") = RS("cinfo")
end if
%>

<tr>
<td>Finding/Problem:
</td>
<td colspan=2> <textarea name="finding" rows="4" cols="50"><%response.write request.cookies("update")("finding")%></textarea>
</td>
</tr>
<tr>
<td>Comment/Response:
</td>
<td colspan=2>
<textarea name="comment" rows="4" cols="50"><%response.write request.cookies("update")("comment")%></textarea>
</td>
</tr>
<tr>
<td>Recommendation:
</td>
<td colspan=2>
<textarea name="recommendation" rows="4" cols="50"><%response.write request.cookies("update")("recommendation")%></textarea>
</td>
</tr>
<tr>
<td>Action taken: </td>
<td colspan=2> <textarea name="action" rows="4" cols="50"><%response.write request.cookies("update")("action")%></textarea>
</td>
</tr>
<tr>
<td>Date of action:
</td>
<td colspan=2>
<textarea name="dateofaction" rows="1" cols="20"><%response.write request.cookies("update")("dateofaction")%></textarea>
</td>
</tr>
<tr>
<td>Lead office: </td>
<td colspan=2> <textarea name="leadoffice" rows="1" cols="20"><%response.write request.cookies("update")("leadoffice")%></textarea>
</td>
</tr>
<tr>
<td>Correction document: </td>
<td> <select id="cinfo" size="1" name="cinfo">
<option value="">Select One</option>
<option value="">-------------</option>
<%
'Get info from database report
'First, open database

'Format query
'format option output
do while not TS.EOF
response.write "<option value='" & TS("cnumber") & "'"
If request.cookies("update")("cinfo")=TS("cnumber") then
response.write " selected"
End if
response.write ">" & TS("cnumber") & "</option>"
TS.MoveNext
Loop

'Close database connection
oConn.Close
set oConn = Nothing

%></select></td>
<td>
<h5>Need to add a document to this list?
<a href="http://updatelessonsession.asp?submitcorrection=1" onClick="document.update.submit()">
Click here</a></td>
</tr>
</table><br />


<!-- Hidden field to verify that search has been submitted -->
<input type="hidden" name="lid" value="<%request.querystring("lid")%>">
<input type="hidden" name="submission" value=1>

<!-- Submit search -->
<input type="submit" value="SUBMIT" name="submit">
<input type="reset" value="CLEAR" name="reset">
</form>

</body>
</html>
Reply With Quote
  #12 (permalink)  
Old 03-06-05, 16:57
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
sorry, I should have spotted this eariler... you have
Code:
<a href="http.../thispage.asp?submitreport=1" onClick="document.update.submit()">
which is basically causing a conflict (more a conflicit of understanding then anything else).

The document.update.submit() is not submitting to the URL you have listed, it will submit to the action of the document.update form.

If you want to submit to a different URL you need to change it to something like this...
Code:
<a href="" onClick="document.update.action='http.../thispage.asp?submitreport=1';document.update.submit()">
or possibly even this would be better...
Code:
<a href="javascript::document.update.action='http.../thispage.asp?submitreport=1';document.update.submit()">
Note: I can never be sure if it is double or single colon in the href.
Reply With Quote
  #13 (permalink)  
Old 03-07-05, 12:50
care99bare care99bare is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
If this works, i'll kiss your feet. I've been working on this FOREVER and no one else has suggested this. However, i'm not lucky enough to have it work right away. I've tried
Code:
<a href="javascript::document.update.action='http.../thispage.asp?submitreport=1';document.update.submit()">
with one and two colons and they both give me an error and don't do anything to the page. I tried
Code:
<a href="" onClick="document.update.action='http.../thispage.asp?submitreport=1';document.update.submit()">
and it gives an error and sends me to a page that says "directory listing denied." Evidently this is a request for the listings of a directory, which it refuses to provide (?). Any other variations?
Reply With Quote
  #14 (permalink)  
Old 03-07-05, 17:14
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
what is the error that the first version gives you. And it should be a single colon by the way....
Reply With Quote
  #15 (permalink)  
Old 03-09-05, 10:15
care99bare care99bare is offline
Registered User
 
Join Date: Sep 2004
Posts: 16
I've tried that line with one and two colons, and both give me the same result - the page loads fine, but when i go to click on the link, i get a little box at the bottom of IE that says "error" with an exclamation point, and nothing else happens. When i try to show the source, it doesn't say anything about an error, so i'm not sure exactly what it is that's causing the problem with the first statement.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On