I have a piece of javascript that accepts text from a textbox and after writing it to the database prepends it to a list of previous items.
$(document).on('click', '.add_file_ins6a', function(){
var job_idx=gl_job_idx;
var ins_content=$('.add_instructions4c').val();
var id=$('.useri').val();
if(ins_content!="")
{
//write new instructions to database
var id=$('.useri').val();
var data="job_id="+job_idx+"&ins="+ins_content+"&client_id="+id+"&key=2";
//alert(data);
$.ajax({
type:"POST",
url:"admin_includes/get_instructions.php",
data:data,
success:function(html2){
$('.add_instructions4').val("");
var split_return=html2.split("|");
var apply="";
apply+="<div class='ins_55'>";
apply+="<p><strong>Date</strong>"+split_return[1]+"</p>";
apply+="<p>"+split_return[0]+"</p>";
apply+="</div>";
$(apply).prependTo('.ins_holder');
}
});//end ajax
}
else
{
alert("FAILED");
}
return false;
});
This works ok but if the user enters a newline in the textbox this displays a '\n' in the prepended listing. When the page is reloaded the '\n' is removed but no newline is created - this could be to do with the
tags or should I be using the tags?
Currently the data is being inputted in the textbox - sent to the server -written to the database and then sent back to the page before being prepended. Should I split the text data where there is a '\n' and add the result to
tags.
Not sure what the best practice here - glad for any opinions.
nl2br()