i’m using “div content editable” html to get value from input keyboard to post with ajax jquery and send to database.
this is my html code
<div class="form_field" name="contentbox" id="contentbox" contenteditable="true">
and my javascript
function mysubmit {
var contentbox = $("#contentbox").html();
var contentboxvalue = "contentboxvalue ='" + escape(contentbox) + "'";
$.ajax({
type: "POST",
url: "<?php echo base_url() ?>admin/data",
data: contentboxvalue,
cache: true,
success: function () {
document.getElementById("contentboxInfo").innerHTML = contentbox;
}
});
}
But I have a problem when I’m updating the value in my database, example: "hello world"
and when I’m updating, ajax post jquery send value:
"
hello world"
How to remove linebreaks (CR/LF), but not <br> tags when submitting to database.
You can use
$.trim()to remove extra white-space in a string.Source: http://api.jquery.com/jquery.trim
Ex.