Have an idea?

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

Add line breaks in dynamic tex using perl

I am using Unverified Perl to pipe in open-ended wording to offer as a numeric response... I need it to look like this (or similar)

1 (user entered agency name)
2 (user entered agency name)

etc... I need them to be on separate lines. BUT I cannot figure out how to insert line breaks into perl. I've tried using "return" and "print". And I've tried using \n within my code. Any help is appreciated, thanks!


[% Begin Unverified Perl

if(VALUE("ls0214")!=999){
    return "1: " . GETVALUE("ls0211") . "\n" . "2: " . GETVALUE("ls0212") . "\n" . "3: " . GETVALUE("ls0213") . "\n" . "4: " . GETVALUE("ls0214");
}
if(VALUE("ls0213")!=999){
    return "1: " . GETVALUE("ls0211") . "\n" . "2: " . GETVALUE("ls0212") . "\n" . "3: " . GETVALUE("ls0213");
}
if(VALUE("ls0212")!=999){
    return "1: " . GETVALUE("ls0211") . "\n" . "2: " . GETVALUE("ls0212");
}
if(VALUE("ls0211")!=999){
    return "1: " . GETVALUE("ls0211");
}

End Unverified %]

asked Mar 3, 2015 by ab3886 (310 points)
retagged Mar 3, 2015 by Walter Williams
Be careful with the respondent entering carriage returns themselves within the O/E responses. That can throw out the neat format you are presenting later in the survey with your Perl code.

One method to prevent carriage returns is to make the O/E fields a single row rather than multiple rows. When the respondent hits enter for a single row O/E field, the page is submitted.

Another fancy method is to write JavaScript that strips the carriage returns from the O/E field upon submission of that respective page.

1 Answer

0 votes
 
Best answer
In order for the line break to show up in the HTML you will need to insert a <br> tag.

return "1: " . GETVALUE("ls0211") . "<br>" . "2: " . GETVALUE("ls0212");
answered Mar 3, 2015 by David Squire Silver Sawtooth Software, Inc. (5,730 points)
selected Mar 3, 2015 by ab3886
Thank you, thank you!! Works perfectly!
...