javascript - Textarea linebreak using ajax -
i got textarea updating description when save using ajax doesn't follow spaces made in textarea.
$('#edit-desc').on('click', function () { var = $('.edit-description'), v = i.val(); if ($(this).hasclass('edit-desc')) { $(this).text('update'); item_val = $('#desc_item').html().replace(/<br>/gi, '\n'); $('.edit-description').show(); $('.edit-description').val(item_val); $('#desc_item').hide(); $('.edit-description').focus(); console.log("you pressed edit"); } else { $(this).text('edit'); item_val = $('.edit-description').val().replace(/\n/g, '<br/>'); 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 edit-item-description php is
<?php 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 typed: b c d in textarea, , save it. shows abcd instead of having spaces /
in it
Comments
Post a Comment