Hi,
I want to collect participants' date of birth in a form (together with other personal details), and then I want to check what their age is and if it is less than 18, I want to give them some kind of warning message so they notice it (much like HTML 5 does when it highlights the form). The purpose isn't to stop them from continuing, but instead to give them a gentle warning that they have possibly entered their DOB wrong. All the other similar questions were asked more than a few years ago when the custom code worked differently, so please don't point me to these posts as they are outdated to say the least! Thank you! :)
Checking if participants' age is less than 18
Best answer by Aanurag_QC
I have created the basic logic here in JS
var from = "15/09/1994".split("/"); ---- Add the value which you receive from the question
var birthdateTimeStamp = new Date(from[2], from[1] - 1, from[0]);
var cur = new Date();
var diff = cur - birthdateTimeStamp;
// This is the difference in milliseconds
var currentAge = Math.floor(diff/31557600000);
// Divide by 1000*60*60*24*365.25
console.log(currentAge);
if (currentAge >=18){
alert("Continue survey");
}
else{
alert("discontinue");
}
You can use alerts that will pop up on their window which will notify the users on the go. If you want to discontinue them from using the survey, then you can store the value in an ED field and use branch flow logic saying if Age_Validator =Yes continue with other blocks else End the survey.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
