Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Show a specific variable (€ or $) depending on a previous select choice

Dear all,

I've got the following problem: I am preparing a questionnaire for both European and American participants. If a specific participant is European or American is prompted at the beginning of the questionnaire  but not which currency they use.
In a later numeric type question I want to add a currency-symbol next to the input box. Which currency symbol ($ or €) is displayed should depend on the previous select question regarding the participants location.
Unfortunately, I do not know yet how to add such a dependent variable.

I would be very grateful if someone could provide me with a solution for this problem!

Thank you very much in advance and best regards.
asked Aug 13, 2021 by Seb0810 (180 points)
edited Aug 13, 2021 by Seb0810

1 Answer

0 votes
Insert the following Perl Script where you want the currency symbol to appear ...
[%Begin Unverified Perl 

 my $Currency_Insert="";

 if(VALUE("LocationQ")==1)
  {  
   $Currency_Insert="$"; 
  }
 else
  {  
   $Currency_Insert="€"; 
  }

 return $Currency_Insert;
 
End Unverified%]


Change "LocationQ" to your previous question name.

Also note I have assumed the "$" symbol is to be displayed if the previous question is "1". So you may need to change the condition in the Perl Script depending on the previous question list / definitions?
answered Aug 13, 2021 by Paul Moon Platinum (101,405 points)
Hello Paul,

thank you very much for your help.

Eventually the "$" sign led to an error message.

As a little addition I would therefore recommend to include a backslash which enables the usage of the sign as a string in perl.

--> ("\$")

King regards!
Try inserting the entity names or entity numbers instead in to the Perl Script ...

Euro: € or €
Dollar: $ or $

Both of these options will work.

Just browse for "entity names" or entity numbers" and you will find a ton of websites list them.

I just tested this and it worked a treat. See the example below ...
[%Begin Unverified Perl 
 
 my $Currency_Insert="";
 
 if(VALUE("LocationQ")==1)
  {  
   $Currency_Insert="$"; 
  }
 else
  {  
   $Currency_Insert="€"; 
  }
 
 return $Currency_Insert;
  
End Unverified%]
As another alternative, you can surround your strings with apostrophes instead of quotation marks.
Thanks for the tip Zachary. Sounds like we have a number of working options available.
...