Problem with form results
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=12191
Printed Date: 30 March 2026 at 9:50pm Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: Problem with form results
Posted By: zaboss
Subject: Problem with form results
Date Posted: 15 October 2004 at 12:33pm
I have a quiz which might have 1 option correct (radio button), or several (checkboxes).
I have problem reading the results when there are more than 1 checkbox selected.
Here it is the code:
'This piece generate the quizpage
'now start the main loop to find all the questions
set RS = MyConn.Execute("SELECT * FROM OE_question WHERE QuizID=" & request.querystring("Quiz") & " ORDER BY Number")
if not RS.EOF then
RS.movefirst
do
& ;nbs p; If RS("QuestionImage") <> "" then
response.write "<p>" & "<img src=imagini/" &
RS("QuestionImage") & ">" & "</p>"
& ;nbs p; Else
end if
response.write "<b>" &
rs("Number") & ". " & rs("Question") &
"</b><p>" & chr(13)
& ;nbs p; 'now display the available options
set ORS = MyConn.Execute("SELECT
* FROM OE_options WHERE QuestionID =" & RS("QuestionID") )
if not ORS.EOF then
ORS.movefirst
do
If RS("QuestionType") = "1" then
response.write "<input type=Radio
Name=""Question" & RS("QuestionID") & """ Value=""Answer" &
ORS("OptionID") & """>" & ORS("Q_Option") & "<br>"
& chr(13)
Else
response.write "<input type=Checkbox
Name=""Question" & RS("QuestionID") & """ Value=""Answer" &
ORS("OptionID") & """>" & ORS("Q_Option") & "<br>"
& chr(13)
End if
ORS.movenext
loop until ORS.EOF
end if
response.write "<p>" & "<HR>"
RS.movenext
loop until RS.EOF
end if
MyConn.close
%>
|
'This piece reads the answers
'now start the main loop to mark all the questions
set RS = MyConn.Execute("SELECT * FROM OE_question WHERE QuizID=" & request.querystring("Quiz") & " ORDER BY Number")
if not RS.EOF then
RS.movefirst
do
response.write "<b>" &
rs("Number") & ". " & rs("Question") &
"</b><br>" & chr(13)
'now check the users answer
answer = request.form("Question" & rs("QuestionID"))
if len(answer)>0 then
'now get rid of the answer, we just want the number on the end
answernum = right(answer,len(answer)-6)
set ORS =
MyConn.Execute("SELECT * FROM OE_options WHERE OptionID=" &
answernum )
if not ORS.EOF then
ORS.movefirst
do
response.write "Răspunsul ales: " &
ORS("Q_Option") & "<br>"
if ORS("tick") = "1" then 'show a tick
response.write "<img
src=""imagini/ASPtick.gif"">"
else 'show a cross
response.write "<img
src=""imagini/ASPcross.gif"">"
end if
response.write " " & ORS("mark") & " : "
& ORS("Response") & chr(13)
summark=summark + ORS("mark")
ORS.MoveNext
Loop until ORS.EOF
end if
else
response.write
"Nu aţi răspuns la această întrebare."
end if
response.write "<p>"
RS.movenext
loop until RS.EOF
end if
response.write "<hr color = ""#0066ff""><font face =
""Georgia, Times New Roman, Times, serif"" color =
""#990000"">Aţi obţinut " & summark & "
puncte din " & totalmark & " posibile.</font>"
%>
|
If there are more than 1 checkbox selected, it doesn't show any answer.
I have checked and the form post all the selected options, but somehow
I fail to read them.
Post form results are
POST Data:
Question33=Answer133&Question34=Answer137&Question 35=Answer141&Question35=Answer142&Question36=Answer1 46&Question37=Answer149&Question38=Answer154&Que stion38=Answer155&Question39=Answer157&Question40=
. . .
|
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Replies:
Posted By: zaboss
Date Posted: 16 October 2004 at 1:13pm
OK, I have narrowed it down. It seems that I couldn't make them read the next answer of the same question...
The form elements are passed as:
Question1=Answer1
Question2=Answer2
Question2=Answer3
Question3=Answer4
etc.
So, what I need is a way of making it reading both (actualy, it has to
be indefinite number as it might be anything from 2 to n) Question.
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Posted By: ljamal
Date Posted: 16 October 2004 at 1:49pm
If the question has multiple answers and the form field has the same name then the valeus should be passed a a comma delineated string like :
Question1=Answer3,Answer4,Answer5
Question2=Answer2,Answer1
etc.
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: zaboss
Date Posted: 16 October 2004 at 3:29pm
That's a step in the right direction, but what if the user doesn't select but only 1 of the multiple choices?
If I use Split function, it won't work.
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Posted By: ljamal
Date Posted: 16 October 2004 at 3:40pm
Split should work even if there is nothing to split. Remember that array begin with 0 not 1.
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: zaboss
Date Posted: 16 October 2004 at 4:03pm
Thanks, it worked. Probably in the first instance I did something wrong, that's why the split function didn't work.
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Posted By: dpyers
Date Posted: 16 October 2004 at 11:48pm
|
I use a binary-type routine for figuring out what boxes have been checked. That way, only one value gets stored in the db.
Example..... CheckBox 1 value = 1 CheckBox 2 value = 2 CheckBox 3 value = 4 CheckBox 4 value = 8 CheckBox 5 value = 16
In the form handler, I just add up the values and store the result. To decipher the result, it's just simple compare and subtract.
The total value if all fields in the example were checked would be 31 If the value I had was 11, that would mean that only CheckBox 1, 2, and 4 were checked. A value of 0 means nothing checked.
-------------
Lead me not into temptation... I know the short cut, follow me.
|
Posted By: ljamal
Date Posted: 17 October 2004 at 9:48am
dpyers wrote:
If the value I had was 11, that would mean that only CheckBox 1, 2, and 4 were checked. A value of 0 means nothing checked. |
Wouldn't 11 be 1,2,and 8?
Interesting system, but for something like this I'd store the answers and questions in separate tables in the database and use a one to many table to link the questions (one) to the answers (many).
I'd do it that way because it's more intuitive for others who may use the data later.
------------- L. Jamal Walton
http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming
|
Posted By: zaboss
Date Posted: 17 October 2004 at 11:41am
I have 1 table which holds the info for tests, one that holds the questions details, one
that holds the options, one that holds the general result and one that holds the full results.
This system is more flexible, because this way you may have an question
which have no correct option (and still be marked), each question may
have pictures, and may have as many options as necesary (each of them
with or without pictures). Also, I may make statistics regarding all
the answers/options.
And by sending only the question and option number I avoid complicate calculus for geting the right result.
The only problem is that I need to make sure when deleting a test to
delete also all the questions and all the options of the questions. It
took me a while until I mastered that.
------------- Cristian Banu
http://www.soft4web.ro - Soft 4 web
|
Posted By: dpyers
Date Posted: 17 October 2004 at 12:20pm
|