Difference between revisions of "Require only one check for grid question"

From Catglobe Wiki
Jump to: navigation, search
(Created page with '== Challenge == Normally, the grid question require one answer for each sub question to navigate to next question. Now, we want it require only one check for the whole grid. == …')
 
Line 2: Line 2:
 
Normally, the grid question require one answer for each sub question to navigate to next question. Now, we want it require only one check for the whole grid.
 
Normally, the grid question require one answer for each sub question to navigate to next question. Now, we want it require only one check for the whole grid.
 
== Example ==
 
== Example ==
[[Image:OneCheckRequired.JPG‎ ]]
+
[[Image:OneCheckRequired.png ]]
 
== Script ==  
 
== Script ==  
 
<source lang="javascript" line="1">
 
<source lang="javascript" line="1">

Revision as of 04:43, 8 December 2009

Challenge

Normally, the grid question require one answer for each sub question to navigate to next question. Now, we want it require only one check for the whole grid.

Example

OneCheckRequired.png

Script

 1 var normalQuestionCheck = questioncheck;
 2 
 3 function extendedQuestionCheck()
 4 {
 5    ErrorMessages.getInstance().clearErrorMessages();//clear old error message
 6    var valid = false;
 7    var q_name = "QUESTION." + "GridQuestionLabel";//question's name = "QUESTION." + question label
 8    var n = $(".grid_inner")[0].rows.length - 1;//number of sub questions
 9 
10    //check if each answer option for each sub question is checked
11    for(var i=0;i<n;i++)
12 	{
13 		$("input:checkbox[name='"+q_name+"."+i+"']").each(
14 			function()
15 			{
16 				if($(this).attr("checked"))
17 					valid = true;				
18 			}
19 		);
20 		if(valid)
21 		break;
22 	}
23 	
24 	if(!valid) showError(quest.requiredtext);
25 	return valid;
26          
27 }
28 
29 function showError(e)
30 {
31 	ErrorMessages.getInstance().showErrorMessage(e);
32 }
33 
34 questioncheck = extendedQuestionCheck;