Last active
December 12, 2017 05:36
-
-
Save davetannenbaum/5eb1439f77f19d16e253 to your computer and use it in GitHub Desktop.
Javascript Qualtrics code to pass previous response to a textbox
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.addOnload(function() | |
{ | |
/* Removes 0s from Text Boxes */ | |
var inputs = $(this.questionContainer).select('input'); | |
inputs.each(function(el) {if (el.value == 0) el.value='';}); | |
/* Creating variable to pass previous response to text fields */ | |
var selectedChoice = "${q://QID5/ChoiceNumericEntryValue/1}"; | |
var selectedChoice = parseInt(selectedChoice); | |
/* Creating variable to pass along embedded data */ | |
var amount = "${e://Field/payment}"; | |
var amount = parseInt(amount); | |
/* Passing along previous response to a particular textbox depending on embedded data assignment */ | |
if (amount == 1) { | |
this.setChoiceValue(1, 1, selectedChoice); } | |
else if (amount == 2) { | |
this.setChoiceValue(2, 1, selectedChoice); } | |
else if (amount == 3) { | |
this.setChoiceValue(3, 1, selectedChoice); } | |
else if (amount == 4) { | |
this.setChoiceValue(4, 1, selectedChoice); } | |
else if (amount == 5) { | |
this.setChoiceValue(5, 1, selectedChoice); } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment