Welcome, Guest
Username: Password: Remember me

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

Filter answers of a question with the answer of another 2 years 10 months 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.

Re: Filter answers of a question with the answer of another 2 years 10 months ago #65927

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4117
  • Thank you received: 760
  • Karma: 346
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 2 years 10 months ago by tpartner.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.114 seconds
Donation Image