Difference between revisions of "Questionnaire - Javascript Fun Tips"

From Catglobe Wiki
Jump to: navigation, search
(Examples)
m (Examples)
Line 60: Line 60:
  
 
[[Disable sub questions in text grids]]  
 
[[Disable sub questions in text grids]]  
 +
 +
[[Show a single question as a dropdown list inside another text grid question]]
  
 
[[Number grid]]  
 
[[Number grid]]  

Revision as of 07:51, 2 February 2009

Basic Hints

Questionnaire viewer is implemented in a way that you can add javascript to manipulate the way your questions are displayed.

jQuery is already included in the viewer, thanks to what javascript has even more powerful effect! (read more about jquery here: http://jquery.com/)

Javascript is a property on both question and questionnaire levels, which means that you can add javascript for each question or for the whole questionnaire.

The most important features are:

  • quest: the current question's object
  • questioncheck: the function called before going Next

quest

There are several important properties in quest object:

  • quest.questions: array of sub questions
  • quest.options: array of answer options
  • quest.setQuestions(Array subQuestions): assign an array of question objects to the sub question list of the current question
  • quest.setOptions(Array options): assign an array of options to the answer option list of the current question
  • quest.setAnswer(string value): assign a value to the question
  • quest.getHTML(): returns the HTML which will be rendered to display the question
  • quest.onInit(): called right after loading the question
  • quest.rotateAnswerOptions(startIndex, endIndex, rotateIndex): rotate answer options in a range specified by startIndex and endIndex, the first item in the range will be rotateIndex
  • quest.rotateSubQuestions(startIndex, endIndex, rotateIndex): rotate sub questions in a range specified by startIndex and endIndex, the first item in the range will be rotateIndex
  • quest.randomizeAnswerOptions(randomSeed, startIndex, endIndex): randomize answer options in a range specified by startIndex and endIndex, the order is unique for each randomSeed
  • quest.randomizeSubQuestions(randomSeed, startIndex, endIndex):randomize sub questions in a range specified by startIndex and endIndex, the order is unique for each randomSeed

questioncheck()

We need to override this function to get rid of the default question check supported by the questionnaire viewer, it is a must when showing more than one questions in the same page. The function returns true when there is nothing wrong and false otherwise.

There is an object which should be used to display errors: ErrorMessages.

  • ErrorMessages.getInstance().clearErrorMessages(): clear all existing error messages
  • ErrorMessages.getInstance().showErrorMessage(msg): show an error message

Examples

Rotate answer options/sub questions

Randomize answer options/sub questions

Drag and drop answer option values

Change Impsys mages

Add an extra row before a sub question in a grid

Hide sub question text column in a grid question

Show a text grid question and a single question in the same page

Change stylesheet of an answer option column in a single grid question

Add an extra column before an answer option column in single grid question

Both horizontal and vertical single grid

Disable sub questions in text grids

Show a single question as a dropdown list inside another text grid question

Number grid

Close to URL

Double columns in text grids

Count down with invisible counter

Force email address

Force number of characters

Change text box size

Maximum text length

Next button count down

Mark answer option with keyboard

Play a list of movies in questionnaire

Play a commercial and automatically go next when it is over in questionnaire