Last active
June 5, 2024 19:38
-
-
Save marketinview/543413f36b34ba8bc71d97d4fd489b9d to your computer and use it in GitHub Desktop.
Qualtrics: Age from Date of Birth. Works with any layout, including Simple. #qualtrics #js #jq #age #birthdate #dob #luxon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/global/luxon.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/global/luxon.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Qualtrics.SurveyEngine.addOnPageSubmit(function() { | |
var DateTime = luxon.DateTime; | |
var birthDate = DateTime.fromFormat(jQuery(this.getQuestionContainer()).find("input[type=text]").val(),"MM/dd/yyyy"); | |
var age = DateTime.now().diff(birthDate, ['years','months']).toObject(); | |
Qualtrics.SurveyEngine.setJSEmbeddedData('age',age.years); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Age in years: ${e://Field/__js_age} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment