Question
Using JQuery change function for many questions
I'm new to Qualtrics and fairly new to Javascript so hope I can make this intelligible.
So this simple bit code changes the value of one box depending on the value of another. (I'm sure it can be done more elegantly.)
My question is: how can I repeat this code for many questions without having to write a separate function for each?
Thanks.
`Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var el1="QR~" + this.questionId + "~1~1~TEXT"; //box 1,1
var el1a=jQuery("[id='" + el1 + "']");
var el2="QR~" + this.questionId + "~1~2~TEXT"; //box 1,2
var el2a=jQuery("[id='" + el2 + "']");
el1a.change(function() {
if (el1a.val().length>0){
if (isNaN(el1a.val()))
{jQuery("[id='" + el2 + "']").val("Not a number");}
else
{jQuery("[id='" + el2 + "']").val("A number");}}
})
});`
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
