Nathan Nathan - 2 years ago 197
Ajax Question

Populating a textarea with New Lines between entries

In my web Api, I'm taking in a list of Social Security Numbers from an Ajax call and I want to populate a textarea with them. What's happening at the moment is it's writing over the line each time, so at the end only one SSN is present. I'd like it to look like


Here is the ajax:

function getSPSssns() {
type: "GET",
cors: true,
crossDomain: true,
contentType: "application/json; charset=utf-8",
url: "http://localhost:64819/api/Participant/getSPSplans",
dataType: "json",
success: function populate(data) {
$.each(data, function (id, elem) {
SSNinput.innerText = SSNinput.innerText + "\n" + elem.Ssn + "\n";

and here is the text area, just in case.

<div class="row" style="padding-top: 8px; white-space:nowrap; width:245px;">
<textarea id="SSNinput" rows="21" class="form-control" placeholder="Paste/Import SSNS Here" style="width: 235px; display: inline-block;"></textarea>

Has anybody come across this before?

Answer Source

When I tried running,

SSNinput.innerText = SSNinput.innerText + "\n" + elem.Ssn + "\n"; 

the placeholder text seemed to be updated.

I changed the above line to:

SSNinput.value = SSNinput.value + "\n" + elem.Ssn + "\n";

and it worked as expected.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download