Add a line break in Javascript | XM Community
Skip to main content
Solved

Add a line break in Javascript

  • June 7, 2019
  • 2 replies
  • 306 views

Forum|alt.badge.img+2
Hello, I am trying to auto fill a text box in a question using Javascript. I want it to appear in a sequential format but I cannot seem to add a line break in the text I want to add. I tried using '\\n', '<'br'>' and '<'br/' >' but nothing is working. How can I accomplish this? Thanks

Best answer by TomG

Make sure your text input question is the Essay type so that it is a `<textarea>`. `<input>` doesn't support line breaks, but `<textarea>` does. Then use \\n: ``` Qualtrics.SurveyEngine.addOnload(function() { jQuery("#"+this.questionId+" .InputText").val("line1\\nline2"); }); ```

2 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • Answer
  • June 7, 2019
Make sure your text input question is the Essay type so that it is a `<textarea>`. `<input>` doesn't support line breaks, but `<textarea>` does. Then use \\n: ``` Qualtrics.SurveyEngine.addOnload(function() { jQuery("#"+this.questionId+" .InputText").val("line1\\nline2"); }); ```

Forum|alt.badge.img+2
  • Author
  • June 10, 2019
@TomG thank you for your response. I would never have guessed the question type would be the issue.