Welcome, Guest
Username: Password: Remember me

TOPIC: Enter E-Mail Twice and making sure both answers are the same.

Enter E-Mail Twice and making sure both answers are the same. 3 years 9 months ago #54987

Hello there,

i think this topic might have been covered somewhere in this forum. However, i didn't find anything.

We'd like to collect emails at the end of our survey.

In order to avoid 'wrong' email-adresses entered into the db, we want participants to enter them twice.

What we do is:

We use 2 "short free text"-fields.

The first field is verified by a regex to ensure that it matches the formal criteria of an email.

Now, for the second field we need a validator, which compares the answers of both fields.

Is something like this possible?
Thanks in advance,
Johan.


EDIT: running v1.90 build:9642
Last Edit: 3 years 9 months ago by johanjohanson. Reason: additional information
The administrator has disabled public write access.

Re: Enter E-Mail Twice and making sure both answers are the same. 3 years 9 months ago #54988

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4297
  • Thank you received: 811
  • Karma: 374
You'll need to use a custom script to achieve this. We could get fancy and disable the "Next" button until the fields match but this is the easiest way:

Set up your survey to use JavaScript and place the following script in the source of the group description or the one of the email questions. Replace "11" and "22" (lines 4 and 5) with the IDs of your two questions. Whenever a field is modified the script compares them and pops up an alert if they don't match.
<script type="text/javascript" charset="utf-8">
 
    $(document).ready(function() {
		var q1ID = 11;
		var q2ID = 22;
		var msg = 'This does not match the other address. Please re-enter it.';
 
		$('#question'+q1ID+' input.text, #question'+q2ID+' input.text').change(function() {
			if ($('#question'+q1ID+' input.text').val() && $('#question'+q2ID+' input.text').val() && $('#question'+q1ID+' input.text').val() != $('#question'+q2ID+' input.text').val()) {
				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: 3 years 9 months ago by tpartner. Reason: Typo
The administrator has disabled public write access.
The following user(s) said Thank You: johanjohanson

Re: Enter E-Mail Twice and making sure both answers are the same. 3 years 9 months ago #55017

hey there,
first of all, thanks for your support. it's much appreciated.
i'm afraid i don't get this to work, yet.

first of all: the test script on your link works flawless. a little pop-up with "test" pops up.
so i guess, there seems to be a problem with the code:


i don't know much about js, but i checked this code on jslint.com.

1. jslint suggests using "!==" instead of "!="
2. there seems to be a ";" missing on the line "$(this).val('')"

i can't say anything about the first suggestion, but with regard to the general structure of the code, the second suggestion should be right.

however, even if i alter these code snippets, the code isn't working for me.

are the questionids really '11' or '22' and nothing like 11111X1X11 or 111111X1X22 (the check is on the same page)? or do i need to add any suffixes or prefixes?
from what i understand, '11' and '22' should be working, as the code concatenates the value of the variable with '#question', so that the code calls the elements with the div id=question11/question22'. nevertheless, i try to give as much information as possible in order to narrow down the problem.

i also placed the code in the group description as well as in both of the email questions. the placement had no effect, but if it had, it would probably be surprising.


i guess my main problem is, that i don't understand the core elements of the code and therefore i'm not able to find out, where the code goes wrong. any ideas?

cheers,
johan
The administrator has disabled public write access.

Re: Enter E-Mail Twice and making sure both answers are the same. 3 years 9 months ago #55022

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4297
  • Thank you received: 811
  • Karma: 374
The code is correct except for the missing semi-colon on line ll and that should only affect very old browsers.

The IDs are just the question IDs, not the full SGQA:
Untitled-1.jpg


Are you getting any JavaScript errors? can you activate a test survey for me to check?
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.
The administrator has disabled public write access.

Re: Enter E-Mail Twice and making sure both answers are the same. 3 years 9 months ago #55023

hey tpartner,
this was exactly what i did. however, it didn't work

as you suggested, i set-up a test survey. and guess what. your code works like charm there. now i'm left with the question, what is wrong in my real survey, as i still don't get it to work there :-/.


thank you so much.

EDIT: I seem to have found the fault. I set the number of rows to '1' for the 'short free text' field. After clearing that information, your code snippet was working. I don't know, if this makes sense :-/.

EDIT2: Maybe someone can add a 'SOLVED' to the subject line of the topic.
LS got an humble student donation from me.
Last Edit: 3 years 9 months ago by johanjohanson. Reason: EDIT2
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.109 seconds
Donation Image