I have the following code, and it is not intuitive to me how I can append the Date to the front end of the newly entered data.
Basically I have a text field that allows editing of the data within. It initially pulls the oldVal from a database, shows it in the td and allows a user to update/edit/add to it. When focus leaves that textarea this method is called and then a php file is called to write to the database.
Here is the td:
<td class="editable-col" contenteditable="true" col-index='4' oldVal ="<?php echo nl2br($res2['status']); ?>"><?php echo nl2br($res2['status']); ?></td>
Here is the javascript method called on 'focusout':
<script type="text/javascript">
$(document).ready(function(){
$('td.editable-col').on('focusout', function() {
data = {};
data['val'] = $(this).html().replace(/\r?\n/g, '<br />');
data['id'] = $(this).parent('tr').attr('data-row-id');
data['index'] = $(this).attr('col-index');
if($(this).attr('oldVal') === data['val'])
return false;
$.ajax({
type: "POST",
url: "updater_1.php",
cache:false,
data: data,
dataType: "json",
});
});
});
</script>
I want to append " March 21, 2017 - " to the front of the new data entered.
I would add "and yet another update here"
So the td ends up looking like this:
March 13, 2017 - Update on cuz blah blah blah
March 19, 2017 - Another update here
March 21, 2017 - and yet another update here
Any suggestions ? I tried to handle it in the updater_1.php file but after many hours it is not as easy as I thought.
Thanks for any and all suggestions.
New code test:
$(document).ready(function(){
$('td.editable-col').on('focusout', function() {
data = {};
data['val'] = getDate() + $(this).html().replace(/\r?\n/g, '<br />');
data['id'] = $(this).parent('tr').attr('data-row-id');
data['index'] = $(this).attr('col-index');
$.ajax({
type: "POST",
url: "updater_1.php",
cache:false,
data: data,
dataType: "json",
});
});
});