Need to put questions on a form on the web

I have an application that needs to go on the web.

Is there a way to take all of the questions from a view (one document per question) and put it on a form on the web using Javascript and then correct the questions hen the user submits the form?

What I am not sure of is that somehow the answers are retrieved from the Javascript code.

thanks

p.

Subject: Need to put questions on a form on the web

An on-demand quiz/test is very do-able (assuming it’s multiple choice or true/false), but JavaScript is not the way to go about it.

Use an agent to create the test in HTML. The answers would be written as radio buttons (input type=“radio”), and would include the question document UNID or NoteID (or a unique lookup key) as part of the field name. You can include a link to validation JS to make sure that all questions have been answered, but that’s all the JS you should use for the test. Make the test form submit to another agent using POST.

The Request_Content item of the documentcontext of the target agent will contain one entry for each question in the format:

field_UNIDforFirstQuestion=c&field_UNIDfor2ndQuestion=a&field_UNIDfor3rdQuestion=d…

Your agent can get the question documents using the UNID (or whatever) that is part of each field name, and check the value against the stored answer.

Subject: RE: Need to put questions on a form on the web

Ok so I am trying to have all of the questions from a view onto a form on the
web. I have the code that will take all of the question an with the use of HTML
have the questions show up on the form. I can see 2 problems right now.

First is the Radio button questions are linked, what I mean is that if I
select True for question 2 and I select true for question 3 then question 2 is
empty. I can only select one answer for all or the True False answers.

1- The Shipper’s Declaration is

a shipping document 

a legal document
for carriers only
a legal document only

2- The Act does not apply if you only receive …

True

False

3- Shipping documents and the outside of containers. …

True

False

Second problem is that I don’t not know how to access the answers from the user.

Any idea how I can continue this code?

I know Stan that I did not follow your way, that is because I found so code
that would help me start.

Thanks
P.

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim AllAnswers As String
Dim vMatOption (1) As String
vMatOption(0) = “True”
vMatOption(1) = “False”

iii = 0
icount = 0
i=0
imatrix = 0
Set db = session.CurrentDatabase
Set docMain = session.DocumentContext

sTitle= "name of the quiz" 'docMain.usemod(0)
Set viewQuestion = db.GetView("Questions")
Set rtQuestionBody = New NotesRichTextItem(docMain,"Questions")
Set rtQuestionbody2 = New NotesRichTextItem(docMain,"Questions")
Call rtQuestionBody.AppendText({table width=550 border=0><tr><td 

bgcolor=#EFEFEF align=center colspan=2>} & sTitle & {})

Set dcQuestion = viewQuestion.GetalldocumentsbyKey("All of the 

Questions")
Set docQuestion = dcQuestion.GetFirstDocument
iii=0
Do Until dcQuestion Is Nothing
iii=iii+1
sQuestionKeyword = “”
sQuestionNo = docQuestion.NumQ(0) ’ question Number
sQuestionInfo = docQuestion.GetItemValue(“Q”)(0) ’ question
sQuestionInputType =docQuestion.GetItemValue(“TypeQ”)(0) ’ type
of question radio or mulpi choice
vQuestionKeyword = docQuestion.GetItemValue(“KeywordsQ”) ’ for
multiple choice all values

	Call rtQuestionBody.appendText({<tr><td width=5% valign=top 

class=QuestionQuestions>} & sQuestionNo &"- "&{})
Call rtQuestionBody.appendText({} & sQuestionInfo & {})
Call rtQuestionBody.AppendText({&nbsp})
Call rtQuestionbody.appendText({<td 95%>

})

	If sQuestionInputType = "MC" Then  ' multiple choice
		Forall answers In vQuestionKeyword
			Call rtQuestionBody.appendText({<input type="} 

& “radio” & {" name=“Answer} & {” value=} & answers & {>})
Call rtQuestionBody.appendText(answers)
Call rtQuestionBody.AppendText({
})
End Forall
Else ’ radio button
Call rtQuestionbody.appendText({

})

		Forall options In vMatOption
			Call rtQuestionBody.AppendText({<td>})
			Call rtQuestionBody.appendText(options)
			Call rtQuestionBody.AppendText({</td>})
			Call rtQuestionBody.AppendText({<td><input 

type=“radio” name=“Matrix} & {” value=} & options & {>})

		End Forall
		Call rtQuestionBody.AppendText({</tr>})
		Call rtQuestionBody.AppendText({</td></tr></table>})
	End If
	Call rtQuestionBody.AppendText({<br>})		
	Call rtQuestionBody.AppendText({</td></tr></table>})
	
	Set docQuestion = 

dcQuestion.GetNextDocument(docQuestion)

Loop		

Call rtQuestionBody.appendText({</td></tr></table>]})
Call docMain.ReplaceItemValue("NumberOfQuestions",iii)

End Sub

&nbsp

Subject: RE: Need to put questions on a form on the web

The problem is that all of the fields have the same name. You need to make sure that every question uses its own field for the answers. That’s just a matter of naming the field using the question document UNID:

Call rtQuestionBody.appendText({<input type="}

& “radio” & {" name=“Answer_} & docQuestion.UniversalID & {” value=} & answers & {>})

It would be nice, though, if you had a smaller unique identifier than the UNID handy (like a field containing @Unique), since the UNID is 32 characters, making the field name ungodly huge.

(NOTE: You are still using an agent to create the test, even if it’s not a freestanding agent that generates all of the web page’s HTML. That is, you aren’t not using my method.)

You will, though, need to create an opening tag on the quiz that submits to an agent, since all of the fields you want to look at are fields that aren’t part of the original form. They can’t be. The “receiving agent” would use the Request_Content field of the DocumentContext:

Dim s As NotesSession

Dim context As NotesDocument

Dim thisDb As NotesDatabase

Dim requestContent As String

Dim answerArray As Variant

Set s = New NotesSession

Set context = s.DocumentContext

Set thisDb = s.CurrentDatabase

requestContent = context.GetItemValue(“Request_Content”)(0)

answerArray = Split(requestContent, “&”)

That will give you an array consisting of “name=value” pairs, so a typical entry in the submitted answers would look like this:

“Answer_5D759BE62A56B9B9852573A8004F75BD=true”

You can use Split with the equals sign to get an array consisting of the fieldname in element 0 and the submitted value in element 1:

“Answer_5D759BE62A56B9B9852573A8004F75BD”

“true”

Use Strright with the underscore to get the UNID of the question document so you can look up the answer, then compare.

Subject: RE: Need to put questions on a form on the web

Some how the agent to retreve the answers is not running. I have placed this code at the top and of the form,

and this at the bottom of the form,

here is my agent from the WebQueryOpen;

.

.

.

If sQuestionInputType = "MC" Then  ' multiple choice

		

		Forall answers In vQuestionKeyword

		Call rtQuestionBody.appendText({<input type="} & "radio" & {" name="answer_} & docQuestion.UniversalID & {" value=} & answers & {>})

			Call rtQuestionBody.appendText(answers)

			Call rtQuestionBody.AppendText({<br>})

		End Forall

		

	Else ' radio button

		Call rtQuestionbody.appendText({<table width="150" border="0" cellpadding=0 cellspacing=0><tr><td>&nbsp</td>})

		

		Forall options In vMatOption

			Call rtQuestionBody.AppendText({<td>})

			Call rtQuestionBody.appendText(options)

			Call rtQuestionBody.AppendText({</td>})

			Call rtQuestionBody.appendText({<td><input type="} & "radio" & {" name="answer_} & docQuestion.UniversalID & {" value=} & options & {></td>})

			

		End Forall

		

		Call rtQuestionBody.AppendText({</tr>})

		Call rtQuestionBody.AppendText({</td></tr></table>})

	End If

	

	Call rtQuestionBody.AppendText({<br>})	

	Call rtQuestionBody.AppendText({</td></tr></table>})

	

	Set docQuestion = dcQuestion.GetNextDocument(docQuestion)

	

Loop		



Call rtQuestionBody.appendText({</td></tr></table>]})

Call docMain.ReplaceItemValue("NumberOfQuestions",iii)

Here is the agent I call to get the answers back from the form, but it is not working I check the log and the agent is not called;

Dim s As NotesSession

Dim context As NotesDocument

Dim thisDb As NotesDatabase

Dim requestContent As String

Dim answerArray As Variant



Set s = New NotesSession

Set context = s.DocumentContext

Set thisDb = s.CurrentDatabase



requestContent = context.GetItemValue("Request_Content")(0)

answerArray = Split(requestContent, "&")

Msgbox "here are the answers for the R C"

Msgbox answerArray

I am of course doing something wrong…

P.

Subject: RE: Need to put questions on a form on the web

OK I have tried this way also but did not work, also my field Request_Content is empty one way or the other… I tried setting the UserAnswers with the Request_Content field using script but again that failed.

'Print |<SCRIPT (“<input type=‘text’ name=‘UserAnwsers’ value=” + “testtest” + “>”)|

any idea way I go wrong… I guess I am far from the right answer Right!

Thanks

p.