Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Multiple choice form to inline script

Hi!

I'd like to use to create a multiple choice form with in-line script. How can I "translate" this option to inline script?

set allow_multiple "yes"

Thanks!

Comments

  • edited November 2020

    I'd like to provide a bit more context to my question.

    The question in the survey is:

    What educational titles do you have?

    And hypothetical answer options are:

    • Level 1
    • Level 2
    • Other

    Respondents can select multiple educational levels. The problem is, once they select "Other" I want them to also fill in what other educational level they may have.


    To do so, I should use in-line script for the multiple choice form.


    If I use inline script, I don't know how to script a multiple choice question (the issue is this line: set allow_multiple "yes")...


    If I use multiple choice preset form, I don't know how to set the condition in "Run if" for the form corresponding to filling in "other" because it is a multiple choice form. So, if a person ONLY selects "other", then it is easy to fill in the "run if" command ([educ]='Other' works fine). But, if a person specifies both "Level 1" and "Other" then it becomes more complicated, as there are multiple combinations of possibly selected answers...


    So, I think the "easiest" way to do this, is to use an inline script. But I am still left with the question of how to "make" a multiple choice question in an inline script...


    Any ideas are much appreciated.


    I attach a small experiment to illustrate my challenge.


  • edited November 2020

    Hi Paula,


    Thanks for the additional info!

    I think it's easiest to use a Run-if statement. Because, as you said, participants could check multiple boxes, you could add a bit of Python code in an inline_script item to determine whether or not to run the additional question. You could put something like the following in its Run tab:


    var.run_additional_question = "no"
    
    if "Other" in var.educ:
        var.run_additional_question = "yes"
    


    Make sure to:

    • Use the square-bracket method for the Run-if statement in the tab of your trial_sequence:
    [run_additional_question] = "yes"
    
    • Put the Python code in the Run phase and place the inline_script item after the first question but before the additional question

    I attached an example experiment.


    Hope this helps!


    Cheers,


    Lotje


    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Thank you very much, Lotje!

    This is a very good solution to my problem.

    Best,

    Paula

  • Great to hear @Paula

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited April 2021

    Hi! I have an additional question :) What if I also want to add a form validator (forced response) to this question?

    I know I need to add this code to an inline script:

    while True:
    	incomplete = False
    	items.execute("form_multiple_choice")
    	if None in [var.educ]:
    		incomplete = True
    	if not incomplete:
    			break
    	else:
    		items.execute("warning_message")
    


    However, I am having trouble in the following line, as it seems OS simply ignores it and the warning message is never displayed:

               if None in [var.educ]:
    
  • It seems to be working by changing " None " to " u'no' " in this way:

    if u'no' in [var.educ]:

  • Hi @Paula ,


    If you don't make a choice after a form_multiple_choice item, the response variable is indeed set to "no". Well done for finding this out! :)


    In the future, printing variables to the console could be helpful:

    print(var.educ)
    


    Or is this exactly what you did?


    Cheers,


    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Thank you for the tip on print(var)!

    I figured it out because the OS documentation mentions that for some forms (ratingscales vs checkboxes), the default is 'None' and for others it is 'no'. I tried both to see which one works, taking a low-tech approach :-) The documentation is quite complete and that helps a lot!

  • Good job, @Paula !

    Did you like my answer? Feel free to Buy Me A Coffee :)

Sign In or Register to comment.