Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Filter answers of a question with the answer of another

Filter answers of a question with the answer of another 5 years 6 days ago #65899

  • hozkarcr
  • hozkarcr's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 1
  • Karma: 0
in my survey
(Question 1) Write your email address
(Question 2) Repeat the email address

i need validate that answers in question 1 and question 2 are equals

It`s possible ?
The administrator has disabled public write access.

Filter answers of a question with the answer of another 5 years 6 days ago #65927

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6313
  • Thank you received: 1407
  • Karma: 546
1) Set up your survey to use JavaScript.

2) Add the following script to the source of the one of the questions. Replace "11" with the first question ID and "22" with the second question ID.

The script puts a listener on the text inputs. If there is a change to one of them and they don't match an alert is popped up and the offending input is cleared.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var q1ID = 11;
		var q2ID = 22;
		var msg = 'The email address does not match, please re-enter it.';
 
		// Listener on the text inputs
		$('#question'+q1ID+' input.text, #question'+q2ID+' input.text').change(function(){ 
 
			var text1 = $('#question'+q1ID+' input.text').val();
			var text2 = $('#question'+q2ID+' input.text').val();
 
			if(text1 != '' && text2 != '' && text1 != text2) {
				alert (msg);
				$(this).val('');
			}
		});
 
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 5 years 6 days ago by tpartner.
The administrator has disabled public write access.
Time to create page: 0.199 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form