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