Aanurag_QC, Sorry, but in the last part of the code that you sent, the "var age_final = age_years;" just takes the value from age_years, so I am confused why you do all the steps in between if age_final ignores them. Also, let me reiterate my previous concern. If the difference between the two variables is only calculated in the new block, I cannot branch this new block based on the difference of the age, can I? Shouldn't I calculate the difference when the participants enter the date of birth? I tried to make it work but failed with this code including the if else statement. Could you take a look please? var age_years = moment().diff("${q://QID81/ChoiceTextEntryValue}", 'years');var now = moment();var before = moment("${q://QID81/ChoiceTextEntryValue}", ["MM-DD-YYYY", "DD-MM-YYYY, moment.ISO_8601"] );var diffDuration = moment.duration(now.diff(before));var years= diffDuration.years(); // 8 yearsvar months = diffDuration.months(); // 5 monthsvar days = diffDuration.days(); var final =
Thanks again, Aanurag_QC .RE: 1) I set an embedded data in the survey flow and then in the Unload function of the birthdate question like this:Qualtrics.SurveyEngine.setEmbeddedData("dob", mo/day/yr);and then updated the code you had sent to:var from = "dob".split("/"); 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.25I assume I will have to change the code in birthdateTimeStamp as well since I want it in the MM/DD/YYYY format. I cannot follow your code. Could you advise how I have to change it? RE: 3) That makes sense. But don't I have to include the code in the unload function of the birthdate question, then? If I include it in the second block, it won't be able to branch anymore, will it?
Aanurag_QC I added the code you suggested and the if else condition to the onload function of the additional block with the fail message:Qualtrics.SurveyEngine.addOnload(function(){ /*Place your JavaScript here to run when the page loads*/ var from = "15/09/1994".split("/"); 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); var age = ????? var agecheck = currentAge - age if(agecheck >"1"){ Qualtrics.SurveyEngine.setEmbeddedData('age_check', "FALSE"); } if(agecheck
Thank you, Aanurag_QC .Sorry about asking again, but do I include the code you sent in the java script of the date of birth question that I sent you? And then where should I subtract the currentAge and Age value?
Thanks, I managed to do it as you suggested. However, is it possible to use the branch logic to exit if a certain number of questions are answered wrong (e.g. any 3 out of 5 questions) instead of all of them?
Thanks SO much!
I do just display a subset of the questions in the block: I only randomly display ONE question of the four questions in the block. It is still not quite clear to me how to make this work. Sorry
Thanks. I had tried this except, I don't seem to be able to select "if block" in the branch. It only lets me select "if question" . And when I select all the questions in the block connected with an "OR" ("If Q1 or Q2 or Q3 or Q4") I cannot select "was displayed" but can only select the branch to work if a certain response was selected. Not sure if this makes sense to you. How can I get to select:"if block" "was displayed"
Qualtrics.SurveyEngine.addOnload(function(){ this.getQuestionContainer().querySelector(".TextEntryBox").type = "Number";});And I use a text entry question. I guess that's the problem? It's just text and respondents are supposed to enter a number in the text box below
Like this? ... It still leaves this grey box above the text entryThanks, the JS code for the number validation worked!
https://www.qualtrics.com/community/discussion/comment/34751#Comment_34751Thanks for your answer but is there another way than just making the text transparent? It looks odd when taking the survey. On the validation issue, it doesn't let me allow only numbers. In the custom validation option, it only lets me add an error message.
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
Sorry, our virus scanner detected that this file isn't safe to download.