| Author |
Topic Search Topic Options
|
loic
Newbie
Joined: 17 June 2003
Location: United States
Status: Offline
Points: 4
|
Post Options
Thanks(0)
Quote Reply
Topic: variable transfer problem Posted: 17 June 2003 at 5:23pm |
|
Hi. I'm actually creating a language placement test.
Each page is composed of a bunch of exercises.
After clicking on the submit button (page1.asp), answers are automatically
corrected (page2.asp) and a score is given to the user.
So far, it’s pretty simple. Here’s a sample of the code which checks the
answers(page2.asp)
Page2.asp
<%
Dim answer1
Select case Request.Form ("1")
Case "yes"
answer1=1
Case "no"
answer1=0
End Select
Dim answer2
Select case Request.Form ("2")
Case "yes"
Answer2=1
Case "no"
Answer2=0
End Select
Dim total1
Total1=answer1+answer2
Response.Write total1
%>
Things get difficult (for me) when it comes to page3,4,5,6 …
In fact, the logic should be like:
page3.asp= total of “page1.asp”+ total of “page2.asp”
page4.asp= total of “page1.asp”+ total of “page2.asp” + total of “page3.asp” …..
My problem is that I don’t know how to call in page 3 a variable (like Dim total1)
I have set up in page 1. Instead, I’m asking the user in page 2 to re-enter his score
in a text-box form field (case) that I call in page 3. It looks like this:
<%
‘this is the total score for page1+page2
Dim totalpage1
Totalpage1=Request.Form ("case")
Dim totalpage2
Totalpage2=answer1+answer2+totalpage1
Response.Write totalpage2
%>
Well, it works fine but (1) it's annoying and (2) there's no integrity
at all as users can re-enter a fake score.
Does anyone have an idea how to simplify this procedure?
Something like having every single result stored in a buffer and being able to call
any variable anytime during the session.
Thanks in advance for your help.
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Post Options
Thanks(0)
Quote Reply
Posted: 17 June 2003 at 5:31pm |
|
You could store it in a session variable.
|
|
|
 |
loic
Newbie
Joined: 17 June 2003
Location: United States
Status: Offline
Points: 4
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 June 2003 at 1:04pm |
|
Michael.
Thanks for your quick answer. I knew it would be something like this as I was referring to it at the end of my post. Anyone could provide me with a sample code to implement Michael’s answer? That would be great for me to have a concrete example I could work on.
Thks
Loic
|
 |
ljamal
Mod Builder Group
Joined: 16 April 2003
Status: Offline
Points: 888
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 June 2003 at 3:26pm |
|
Personally. I like to stay away from session variables as they are just glorified cookies. Just use a cookie to store the information.
|
|
|
 |
michael
Senior Member
Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 June 2003 at 3:52pm |
If you use a cookie or session is up to you, cookie has the advantage that the user could pick it back up if he looses connection. To get some insight on cookies check this site out: http://www.w3schools.com/asp/asp_cookies.asp
|
|
|
 |
loic
Newbie
Joined: 17 June 2003
Location: United States
Status: Offline
Points: 4
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 June 2003 at 4:17pm |
|
this website looks good. Thanks Michael. Cookies have such a bad reputation that I wasn't sure it would be appropriate. Nevertheless, I'm going to give it a shot.
Someone else posted on another forum the following answer:
"couldn't you just pass the values from page to page by populating hidden text boxes?
you could just write the form and the values in one swoop:
<%
response.write("<form name='page1'>")
response.write("<input type='hidden' name='answ1' value=" & answer1 & ">")
response.write("<input type='hidden' name='answ2' value=" & answer2 & ">")
response.write("<input type='hidden' name='tot1' value=" & total1 & ">")
response.write("</form>")
%>
(the values will be populated by your SELECT CASE statements) couldn't you just pass the values from page to page by populating hidden text boxes?
FYI
|
 |
loic
Newbie
Joined: 17 June 2003
Location: United States
Status: Offline
Points: 4
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 June 2003 at 5:16pm |
|
quick question:
<% Response.Cookies("scorepage1") = value %>
I can't setup a definitive value (like 1,2, ...) as i've no idea what the score is going to be. Therefore I was wondering if a Cookie could equal a variable instead of a value? Something like:
<%
Dim score
score=answer1+answer2 ...
'cause I need the user to see his score
Response.write score
Response.Cookies("total")= ????
'??? being the variable 'score' I would like to call
%>
Any idea or sugestion?
|
 |