-1

This question might be a long shot, but I am unable to find anything within the googles.

Currently, I am using javascript that gets the textarea input and downloads it into a txt file.

HTML input in form:

<textarea rows="7" type="text" id="detailsField" placeholder="Enter call details"></textarea>

If the text area contains multiple lines, the output places those multiple lines into one long line.

Example: What was typed into text area:

Details1 details2
details3

What the output looks like in the txt file:

Details1 details2 details3

Javascript for downloading form into a txt file:

// EXPORT FORM TO TXT FILE
function buildData (){
    var txtData = 
        "Time & Date of Submission: "+$("#timeField").val()+
        " "+$("#dateField").val()+
        "\r\nClient's Name: "+$("#nameField").val()+
        "\r\nCompany Name: "+$("#companyField").val()+
        "\r\nDetails: "+$("#detailsField").val();



    return txtData;
    }
        $(function(){
        $("#submitLink").click(function(event){
        var txtData = buildData();
        $(this).attr('download','Call Log.txt')
        .attr('href',"data:application/octet-stream;base64,"+Base64.encode(txtData));
    });
});

I am not very strong minded with JS so as much detail as possible would be appreciated.

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
Walki
  • 1
  • 2
  • Possibly duplicate https://stackoverflow.com/questions/863779/javascript-how-to-add-line-breaks-to-an-html-textarea – CInvt Apr 06 '18 at 02:10
  • 1
    @CInvt after trying at those solutions, can't say they helped me – Walki Apr 06 '18 at 02:16
  • The code that you have doesn't remove the lines, so the issue isn't there. The issue is in either how the octet-stream is saved to a file, or how the text file is displayed. You didn't give any details about those, so we cannot help. – Racil Hilan Apr 06 '18 at 02:16

1 Answers1

0

Try following way if it is work for you I used regular expression:

function buildData (){
    var txtData = 
        "Time & Date of Submission: "+$("#timeField").val()+
        " "+$("#dateField").val()+
        "\r\nClient's Name: "+$("#nameField").val()+
        "\r\nCompany Name: "+$("#companyField").val()+
        "\r\nDetails: "+$("#detailsField").val().replace(/(\r\n|\n|\r)/gm," ");

    return txtData;
}
Hanif
  • 3,739
  • 1
  • 12
  • 18