Automatically add new lines

Automatically add new lines

I want to ask a text entry question where I don't know how many answers respondents will want to list. E.g., list all the footballers that come to your mind. How can I get Qualtrics to automatically add another line, if a respondent has used up the number of text entry fields that first show up?

Tagged:

Best Answers

  • ShashiShashi India Wizard ✭✭✭✭✭
    edited November 2018 Accepted Answer

    Hello @automaticadd ,

    Solution 1: You can go for loop and merge

    Solution 2: If you can specify the maximum number that the user can enter in the footballers kown question. Then in the next question you can have form question type and can apply display logic at option level. Eg: the display logic at option 3 will be if number is less than or equal to three.

  • TomGTomG Raleigh, NC Wizard ✭✭✭✭✭
    Accepted Answer

    @automaticadd,

    Or, if you can write JS, you can have a text form with the maximum number of footballers and hide all but the first input field. Then as the respondent enters something in a field, unhide the next empty field.

  • TomGTomG Raleigh, NC Wizard ✭✭✭✭✭
    Accepted Answer

    @automaticdd - This will be a bit beyond basic JS. Here is a resource for learning html, css, JS, and jQuery (each is a prerequisite for the next): https://www.w3schools.com/

Answers

  • automaticaddautomaticadd Community Member Qubie ✭

    @Shashi thanks for your answer. I tried loop and merge (solution 1) and perhaps I didn't understand it properly but it seemed that all versions always referred to a previous answer. I actually need additional text entry fields within the same question if a respondent uses all text entry fields I provide.
    I have the same problem with solution 2; they would need to indicate first how many they plan to list. But I want them to rather go ahead intuitively, until they can't come up with any more..
    Nonetheless, thanks for your answer.

  • automaticaddautomaticadd Community Member Qubie ✭

    @TomG Thank you for taking the time. Your answer sounds promising. I don't want to limit the answer choices so I would have to go for an unrealistic high number of options. My problem, however, is that I have never written a javascript.
    Is there any other way of doing this? Is there no function that would automatically add additional entry fields if a respondent uses all the fields available. I feel like I've come across this many times in filling out surveys?!

  • TomGTomG Raleigh, NCCommunity Member Wizard ✭✭✭✭✭

    @automaticadd said:
    Is there any other way of doing this? Is there no function that would automatically add additional entry fields if a respondent uses all the fields available. I feel like I've come across this many times in filling out surveys?!

    No, the only way to do it is with JavaScript.

  • automaticaddautomaticadd Community Member Qubie ✭

    Ok, thanks!

  • automaticaddautomaticadd Community Member Qubie ✭

    Hi again

    I realised there is the option of implementing a display logic on choice level. I used a text entry question and set the number of Form Fields to 30. The first three form fields are unconditional and should show up no matter what. Within this question XY, e.g. for the fourth choice/text entry field I have the display logic: "Display this Choice only if the following condition is met: 'Question' 'Q XY' 'Choice 2' 'Is Not Empty'.

    When I preview the survey and put some characters in Choice 2, I don't get an additional form field. Is there an obvious mistake in my logic?

    Thanks in advance

  • TomGTomG Raleigh, NCCommunity Member Wizard ✭✭✭✭✭

    Yes, choice display logic is applied on the server before the page gets sent to the browser. The only way to do it dynamically is with JS.

  • automaticaddautomaticadd Community Member Qubie ✭

    @TomG once again, thanks for your quick answer. I have no experience with writing in javascript. Do you think it is possible to learn JS within a reasonable amount of time to be able to write such a "feature" that would dynamically unhide form fields? If yes, can you recommend where/what I should start with?

  • automaticaddautomaticadd Community Member Qubie ✭

    @TomG Thanks!

  • riceballriceball Community Member Qubie ✭

    Hi @automaticadd I hope that your account is still active and you get this! I'm just wondering if you found a solution to this problem outside of JavaScript - I need to do the same thing ("list all classes you've taken" which could be 1 or 100), and while I could probably write the JavaScript, it's definitely beyond the capabilities of some of my collaborators to understand. It seems like just leaving 50 blank lines is the best option, which I can just put on its own page, but that's going to make a mess out of the response table.

  • automaticaddautomaticadd Community Member Qubie ✭

    Hi @riceball. I was lucky enough to have a friend write the javascript for me because there really does not seem to be another solution. I'm happy to share the code but I'm not sure if that is what you are after?

  • riceballriceball Community Member Qubie ✭

    Hi @automaticadd, I was hoping there was a non-code way so I could share with my non-technically minded coworkers how to do it themselves, but doing it any way is better than not doing it at all! I'd really appreciate if you shared to code tidbit. That would save me an incredible amount of work trying to figure it out. Thank you!!

  • automaticaddautomaticadd Community Member Qubie ✭

    sure. You can find the code below. it is for the addOnload section. the way it works is that I created 100 text entry fields. with the code below, 15 are initially visible, the rest is hidden. whenever you click or tab in to the last field visible, an additional field appears. hope this helps, best of luck.

    {
    jQuery("#"+this.questionId+" .InputText").focus( function() {
    var isInputText = document.activeElement instanceof HTMLInputElement && document.activeElement.type == 'text';

        console.log(isInputText);
    
        if (isInputText)
        {
            tbody2 =  document.activeElement.parentNode.parentNode.nextSibling.nextSibling.show()//style.display = 'inline-block';
        }
    });
    
    var initialFields = 15;
    
    var choices = this.getChoiceContainer();    
    
    //choices.hide();
    
    //alert(choices);
    
    var tbody = choices.getElementsByTagName('tbody');
    //alert(tbody[0].childNodes.length);
    
    childs = tbody[0].childNodes;
    
    
    for (i=(initialFields*2); i <childs.length; i++)
    {
        if (childs[i].style) {childs[i].style.display = 'none';}
    }
    
    
    this.questionclick = function(event,element)
    {
        var isInputText = element instanceof HTMLInputElement && element.type == 'text';
    
    
        if (isInputText)
        {
            tbody2 = element.parentNode.parentNode.nextSibling.nextSibling.show()//style.display = 'inline-block';
        }
    }
    

    });

Sign In to Comment