PennController for IBEX › Forums › Support › Output Text based on Selection in Dropdown Menu
- This topic has 2 replies, 2 voices, and was last updated 4 years ago by
AndreasK.
-
AuthorPosts
-
July 8, 2020 at 9:16 am #5775
AndreasK
ParticipantHi 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 #5777Jeremy
KeymasterHi 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 #5780AndreasK
ParticipantHi Jeremy,
Thank you for your explanation and for the code. It works perfectly.
Andreas
-
AuthorPosts
- You must be logged in to reply to this topic.