Nathan Nathan - 6 months ago 21
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

XXX-XX-XXXX New Line

Here is the ajax:

function getSPSssns() {
$.ajax({
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>
</div>


Has anybody come across this before?

Answer

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.