Have an idea?

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

How do I use javascript to concatenate several responses into a single text string and assign it to a variable

I need to take several text string responses and concatenate them into a single string and assign it to a variable.

Can this be done with Javascript?
asked Nov 16, 2012 by pmj7671 (140 points)

2 Answers

0 votes
You can do this by creating a free format hidden variable.

Here's a simple example where you can blend a string with a value of a question already captured within conditional IF statements ...

<input name="HdQ100_TEXT" type="hidden" value="
Begin Unverified Perl

 my $Q100_text=0;
if (VALUE("HdX1_CODE")==1)
  $Q100_text="accounting services &".(VALUE("Q50"));

elsif (VALUE("HdX1_CODE")==2)

 return $Q100_text;
End Unverified
answered Nov 16, 2012 by Paul Moon Platinum (98,670 points)
hdx1_code and Q50 questions must appear at least one page-break earlier.
Thanks Paul and Bahadir.  Is there a way to do this with JavaScript rather than Perl?

A freeform question takes five inputs.  I want to take these five inputs and concatenate them into a single string so that: Q1+Q2+Q3+Q4+Q5 = Q6 alpha string.

0 votes
In JavaSCript you use the plus symbole (+) to concatenate strings. So if you want to use JavaScript I would create Q6 as a free format hidden variable on the same page as Q1 through Q5 with value = "". Then, in custom JavaScript verification (so that it runs on page submit) you can put in something like

SSI_GetFormObject("Q6").value = SSI_GetValue("Q1") + SSI_GetValue("Q2") + SSI_GetValue("Q3") + SSI_GetValue("Q4") + SSI_GetValue("Q5");

the SSI_Get... functions were introduced in SSI Web 7 so if you are on an older version you can use


to get and set form object values instead.
answered Nov 16, 2012 by Jeff Forkner Bronze (2,875 points)