I got a textarea for updating a description but when i save it using ajax it doesn't follow the spaces i made in the textarea.
$('#edit-desc').on('click', function () {
var i = $('.edit-description'),
v = i.val();
if ($(this).hasClass('edit-desc')) {
$(this).text('UPDATE');
item_val = $('#desc_item').html().replace(/
/gi, '\n');
$('.edit-description').show();
$('.edit-description').val(item_val);
$('#desc_item').hide();
$('.edit-description').focus();
console.log("you pressed the EDIT");
} else {
$(this).text('EDIT');
item_val = $('.edit-description').val().replace(/\n/g, '
');
item_id = $('#collection_item_id').val();
$('.edit-description').hide();
$('#desc_item').show();
$('#desc_item').html(item_val);
$.post('php/edit-item-description.php', {item_id: item_id, item_val: item_val}, function(e){
location.reload();
});
}
$(this).toggleClass('edit-desc');
});
and on my edit-item-description php is
session_start();
include 'connect.php';
include 'exec/functions.php';
$edit['item_id'] = $_POST['item_id'];
$edit['brand'] = nl2br($_POST['item_val']);
if(editCollectionName($edit)){
echo "success";
}else{
echo "something wrong";
}
?>
When i typed:
A
B
C
D
in the textarea, and save it. It shows ABCD instead of having spaces /
in it