Add a line break in Javascript | XM Community
Solved

Add a line break in Javascript

  • 7 June 2019
  • 2 replies
  • 150 views

Badge +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
icon

Best answer by TomG 7 June 2019, 22:45

View original

2 replies

Userlevel 7
Badge +27
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");
});
```
Badge +2
@TomG thank you for your response. I would never have guessed the question type would be the issue.

Leave a Reply