in my survey, people are asked to list tools they use and I chose form field as question type. Anyway, I would like my respondents to add as many text entrys as they need, currently the number of text entry is predetermined by me. I think of something like a "add choice" button.
So far, I've found this and it works: https://community.qualtrics.com/XMcommunity/discussion/4150/enable-respondent-to-add-extra-response-fields
var that=this.questionId;
jQuery("#" this.questionId " tr.ChoiceRow:not(:lt(1))").hide();
jQuery("<input type='button' id='add' value='Add field' name=' ' />").insertAfter("#" this.questionId " tr.ChoiceRow:last");
jQuery("#add").on('click',function(){
var c= jQuery("tr.ChoiceRow:visible").length;
jQuery("#" that " tr.ChoiceRow:eq(" c ")").show();
});
but you have to change the question type "to matrix table", which I would like to avoid. I don't know what and how to adjust the code in order to make it work for form field type of question.
Thanks!
CodePudding user response:
That code actually adds the button in the wrong place and it could be streamlined.
This will work for a form:
Qualtrics.SurveyEngine.addOnload(function() {
var cs = jQuery("#" this.questionId " .ChoiceStructure");
cs.find("tr:not(:lt(1))").hide();
cs.append("<input type='button' id='add' value='Add field' name=' ' />");
jQuery("#add").on('click',function(){
var c = cs.find("tr:visible").length;
cs.find("tr:eq(" c ")").show();
});
});