在textarea中的多行上执行更新功能

I have a textarea that posts each line to a database and then pulls that data to display it on a separate text area. I have a function that when called calls a php update function. This updates the line in the database corresponding to the line in the textarea. What I want to do is when this update function is called, I want all the lines to be updated, not just the one that is selected. This is because at the moment I have to manually select each line to update if a change is made anywhere to enusre the lines and indentation are the same.

    <script>
    var lineNo = 0;
    var lineText = "";
    var ta;
    var numOfSpaces;


   function update(e) {
       ta = $("#textEditor")[0];
     lineNo = ta.value.substr(0, ta.selectionStart).split(/?
|/).length;
      lineText = ta.value.split(/?
|/)[lineNo - 1];
       numOfSpaces = lineText.split(/\s/).length - 1;


      console.log(" line num: " +lineNo+ " line data: " + lineText);



        $.ajax({

         url: "update1.php",
         method: "POST",
         data: {lineN: lineNo, lineT: lineText},
         dataType: 'text',
         success: function(data){

          console.log(data);
         }
       });
     }

           $('#textarea').keydown(update).mousedown(update);

The above is the function which catches the text at a line and the corresponding line number. It passes the information to the following php file

    <?php


    $linec = $_POST['lineT'];
    $linenumber = $_POST['lineN']



     $update = "UPDATE Code_Stream1 SET Line_Code='$linec' where LineNumber='$linenumber' ";

    $resultinsert = $conn->query($update);

    echo $update;


?>

ps I have a connection to the database but didn't include above

Maybe I misunderstand your question, but couldn't you simply use .setSelectionRange on the textarea to select all text?

$('#textEditor').on('focus', function(e) {
    // setTimeout skips to the next tik in the eventLoop
    // preventing timing issues in some browser
    setTimeout(function() {
        e.currentTarget.setSelectionRange(0, e.currentTarget.value.length);
    }, 0);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<textarea id="textEditor" rows="4">
    Line 1
    Line 2
    Line 3
    Line 4
</textarea>

</div>