Millisecond Forums

When to use

https://forums.millisecond.com/Topic20021.aspx

By JL - 11/1/2016

Hi,

I understand that I need to use this syntax for combining text and properties / values and when defining the items attribute in a stimulis.

But, Do I also need to use this syntax when inserting a value within a textbox (survey) element or with a boolean expression as seen in the following example? 

<textbox Age>
/ Caption = “Age”
/ mask = integer
/ range (16,80)
/ value.ageans = <%textbox.Age.response%>
</textbox>

<dropdown Gender>
/ caption = "Select Gender"
/ options = ("female", "male")
If (<%dropdown.gender.caption>% == “female”)
{value.genderans=0}
Else
{value.genderans=1}
</dropdown>

Thanks!
By Dave - 11/2/2016

I'm sorry, but this code does not make sense:

<dropdown Gender>
/ caption = "Select Gender"
/ options = ("female", "male")
If (<%dropdown.gender.caption>% == “female”)
{value.genderans=0}
Else
{value.genderans=1}
</dropdown>

#1: You don't want to access the dropdown's caption. You want to query its response.
#2: You cannot just put conditional logic in an element and expect it to work. Conditional logic needs to reside in event attributes (/ontrialbegin, ontrialend, etc.). A <dropdown> has no event attributes -- the <surveypage> the dropdown resides on has.

<surveypage mypage>
/ ontrialend = [if (dropdown.gender.response == "female") values.genderans = 0 else values.genderans = 1; ]
/ questions = [1=gender; ...]
...
</surveypage>

<dropdown Gender>
/ caption = "Select Gender"
/ options = ("female", "male")
</dropdown>
By JL - 11/2/2016

Thanks!

One more question regarding the above example:

/ value.ageans = textbox.Age.response

If i insert this line of code into a <surveypage> could I use the the value extracted from the textbox.age.response as an integer? If not, how is it possible to get the age as an integer so it can be used for mathematical expressions later on?


By Dave - 11/2/2016

> / value.ageans = textbox.Age.response

This line is not valid syntax. If you "insert this line of code into a <surveypage>", it will not do anything. Just like with the dropdown, what you want is

<surveypage mypage>
/ ontrialend = [if (dropdown.gender.response == "female") values.genderans = 0 else values.genderans = 1; ]
/ ontrialend = [values.ageans = textbox.Age.response]
/ questions = [1=gender; 2=age]
...
</surveypage>


By JL - 11/2/2016

Ok. Just to make sure: A value that I define can only be updated as part of an event attribute and never as a standalone command line like I wrote above?
By Dave - 11/2/2016

Yes.