Welcome, Guest
Username: Password: Remember me

TOPIC: Scoring multiple choice questions

Scoring multiple choice questions 2 years 7 months ago #71089

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Thank you received: 1
  • Karma: 0
I think I'm past my limit for forum questions, but I've hit a wall once again. I have a series of multiple choice questions that I'd like to score via hidden questions. The scoring logic it slightly different for each question, but here are some examples:

Question 1:
choice A
choice B
choice C

If one choice is checked, score is 3, if two are checked, score is 4, if three checked, score is 5.

Question 2:
choice A
choice B
....
choice K

If one is checked, score is 2, if more than one, score is 3.

I see having a page of hidden questions that will score each question on the previous page. This survey can be group-by-group or all in one (makes no difference). If I can figure out how to do it for one question, I can do the other others, but so far I haven't been able to cobble together a script from code snippets in the forums or elsewhere.
Thanks,
Matt
The administrator has disabled public write access.

Re: Scoring multiple choice questions 2 years 7 months ago #71092

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
misterdot-

Here's how you would do this in 1.92 RC1 (which should be released this week).

Say your questions 1 and 2 are named Q1 and Q2, and the answer code values are named A, B, C.

Create four new questions: Sum1, Score1, Sum2, Score2, all of type Equation.

The text for each of them is as follows:

Sum1:
{sum(Q1_A, Q1_B, Q1_C)}

Score1:
{if(Sum1==1, 3, if(Sum1==2, 4, if(Sum1==3, 5, 0)))}

Sum2:
{sum{Q2_A, Q2_B, Q3_C)}

Score2:
{if(Sum2==1, 2, if(Sum2>1, 3, 0))}

This will work in any survey mode (question, group, or all-in-one).

/Tom
Last Edit: 2 years 7 months ago by TMSWhite.
The administrator has disabled public write access.

Re: Scoring multiple choice questions 2 years 7 months ago #71120

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4049
  • Thank you received: 739
  • Karma: 341
While 1.92 RC1 (thanks to TMSWhite's Expression Manager) will have some wonderful new capabilities, it should be noted that this will be a release candidate and is not recommended for production surveys.

For the stable 1.91 version, you can do the following:

In each case, add a short-text question to the same page as the multiple-options question. We'll hide this question and load it with the score.

For the first case, add the following script to the source of the short-text. Replace "QQ" with the multiple-options question ID and "HH" with the short-textquestion ID.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Call the function with the question IDs
		calcScore1(QQ, HH);
 
		function calcScore1(q1ID, qScoreID) {
 
			// Hide the score question
			$('#question'+qScoreID).hide();
 
			// Interrupt next/submit function 
			$('#movenextbtn, #movesubmitbtn').click(function(){
 
				// Count the checked boxes and calculate the score	
				// If one choice is checked, score is 3, if two are checked, score is 4, if three checked, score is 5.
				var score;
				var count = $('#question'+q1ID+' input.checkbox:checked').length;
 
				if(count == 0) {
					score = 0;
				}
				else if(count == 1) {
					score = 3;
				}
				else if(count == 2) {
					score = 4;
				}
				else if(count > 2) {
					score = 5;
				}
 
				// Load the score question
				$('#question'+qScoreID+' input.text').val(score);
 
				return true;
			});
		}
	});
 
</script>



For the second case, add the following script to the source of the short-text. Replace "QQ" with the multiple-options question ID and "HH" with the short-textquestion ID.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Call the function with the question IDs
		calcScore2(QQ, HH);
 
		function calcScore2(q1ID, qScoreID) {
 
			// Hide the score question
			$('#question'+qScoreID).hide();
 
			// Interrupt next/submit function 
			$('#movenextbtn, #movesubmitbtn').click(function(){
 
				// Count the checked boxes and calculate the score	
				// If one is checked, score is 2, if more than one, score is 3				
				var score;
				var count = $('#question'+q1ID+' input.checkbox:checked').length;
 
				if(count == 0) {
					score = 0;
				}
				else if(count == 1) {
					score = 2;
				}
				else if(count > 1) {
					score = 3;
				}
 
				// Load the score question
				$('#question'+qScoreID+' input.text').val(score);
 
				return true;
			});
		}
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 2 years 7 months ago by tpartner.
The administrator has disabled public write access.

Re: Scoring multiple choice questions 2 years 7 months ago #71125

  • misterdot
  • misterdot's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Thank you received: 1
  • Karma: 0
Once again, tpartner, thanks so much -- works perfectly as usual.

TMSWhite, EM looks really great and it will be a huge gain for non-programmers such as myself. I was hoping we'd get to use it for our current project, but I don't think it's going to make it in time for us to go into production. I appreciate the posts, though, because they'll be really useful in the future as a reference. Is 1.92 different from the planned 2.0, or are they now essentially the same?
The administrator has disabled public write access.

Re: Scoring multiple choice questions 2 years 7 months ago #71129

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
misterdot-

The version of Expression Manager in 1.92 is significantly more powerful and well integrated into LS than the one in 2.0a, but we expect to upgrade the 2.0 branch to use that functionality over the next several months. I've updated the EM documentation to reflect what it can 1.92 can do.

/Tom
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.349 seconds
Donation Image