| Author |
Topic Search Topic Options
|
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
Topic: Problem with form results 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=
. . .
|
Edited by zaboss
|
|
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
ljamal
Mod Builder Group
Joined: 16 April 2003
Status: Offline
Points: 888
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
ljamal
Mod Builder Group
Joined: 16 April 2003
Status: Offline
Points: 888
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |
ljamal
Mod Builder Group
Joined: 16 April 2003
Status: Offline
Points: 888
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |