PennController for IBEX › Forums › Support › Output Text based on Selection in Dropdown Menu
- This topic has 3 replies, 3 voices, and was last updated 1 week, 3 days ago by
kathy.
-
AuthorPosts
-
July 8, 2020 at 9:16 am #5775
AndreasKParticipantHi Jeremy,
I would like to print text, depending on the selection that participants made in a Dropdown menu in the previous trial. I’ve written this code:
Sequence( "intro", "check") newTrial("intro", newDropDown("hand", "...") .add("left", "right") .print() .log() .wait() , newVar("handedness") .global() .set(getDropDown("hand")) , newButton("Next") .print() .wait() ) newTrial("check", newText(getVar("handedness").test.is("left")?"Option1":"Option2") .print() , newText(getVar("handedness").test.is("left")?"Option3":"Option4") .print() , newButton("Next") .print() .wait() )What I would like is the following:
– When participants select ‘left’, they see ‘Option1 Option3’ after they click on the button.
– When participants select ‘right’, they see ‘Option2 Option4’ after they click on the button.However, the code always prints ‘Option1 Option3’, regardless of which option from the DropDown menu is selected.
Could you help with that?
Andreas
July 8, 2020 at 11:57 am #5777
JeremyKeymasterHi Andreas,
You’re mixing up plain javascript code and PennController code. The PennController test commands are meant to be used autonomously (ie. as a block of commands separated by commas, or inside a callback command for example, just like a newText command for example) not inside a javascript triconditional like this. You need to use success and/or failure so you can execute PennController commands conditionally. So this is what you second trial should look like:
newTrial("check", newText("optionA").print(), newText("optionB").print() , getVar("handedness").test.is("left") .success( getText("optionA").text("Option1"),getText("optionB").text("Option3") ) .failure( getText("optionA").text("Option2"),getText("optionB").text("Option4") ) , newButton("Next") .print() .wait() )Jeremy
July 9, 2020 at 7:34 am #5780
AndreasKParticipantHi Jeremy,
Thank you for your explanation and for the code. It works perfectly.
Andreas
December 1, 2025 at 11:22 am #11135kathy
ParticipantHi Jeremy,
I have a similar request. I have a dropdown menu asking if participants were born in the US (yes/no). If “no” is selected, I would like a further question (in which country they were born) + text input box to appear, as well as the question of when they moved there (Month dropdown and Year Text Input). Currently there is an additional page for these two questions which I would like to get rid of.
These are currently the bits of code:
newText(“borninus”,”Were you born in the United States?”)
,
newDropDown(“borninus”,”select”)
.settings.add(“yes”,”no”)
.size(120,25)
.settings.log(),
newCanvas(“borninuscanvas”,700,80)
.settings.add(0,0,getText(“borninus”))
.settings.add(300,0,getDropDown(“borninus”))
.center()
.print(),
newButton(“next”,”Next”)
.center()
.print()
.wait()
)newTrial(“pagethree-birthplace”,
newText(“skip”,”If you were born in the United States, you may skip this page by clicking \”Next\”.”)
.center()
.print()
,
newText(“countryofbirth”,”In which country were you born?”)
,
newTextInput(“countryofbirth”,)
.log()
.size(300,25)
,
newCanvas(“countryofbirthcanvas”, 700, 120)
.settings.add(0,50, getText(“countryofbirth”))
.settings.add(300,50, getTextInput(“countryofbirth”))
.center()
.print()
,
newText(“movedtous”, “When did you move to the United States?”)
,
newText(“monthmovedtous”, “Month”)
,
newText(“yearmovedtous”, “Year”)
,
newDropDown(“monthmovedtous”,”select”)
.settings.add(“January”,”February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”)
.size(100,25)
.settings.log()
,
newTextInput(“yearmovedtous”,)
.log()
.size(80,25)
,
newCanvas(“movedtouscanvas”, 700, 100)
.settings.add(0,40, getText(“movedtous”))
.settings.add(300,20, getText(“monthmovedtous”))
.settings.add(420,20, getText(“yearmovedtous”))
.settings.add(300,40, getDropDown(“monthmovedtous”))
.settings.add(420,40, getTextInput(“yearmovedtous”))
.center()
.print()
,
newButton(“next”, “Next”)
.center()
.print()
.wait()
)I’ve tried all kinds of things inlcuding .success / .failure, .callback and if…else codes, but nothing has worked well so far (probably because I keep overlooking something, but ChatGPT was similarly unhelpful). Could you help me find a way how best to go about this?
Thanks so much and best,
Kathy -
AuthorPosts
- You must be logged in to reply to this topic.