Question

I have a nicedit textarea. When I click a button to send the data to a jquery $.get function, it doesnt send the formatting and just adds a tab space to the front of the data.

heres the form

<form id="myFrm">
 <input type="hidden" id="page_ref" name="page_ref"  value="<? echo $page_ref; ?>"/>
 <input type="hidden" id="template_ref" name="template_ref" value="<? echo $template_ref; ?>"/>
 <input type="hidden" id="box_id" name="box_id"/>
 <textarea name="edit_content" id="edit_content"></textarea>
 <div class="button">Save</div>
</form>

the textarea #edit_content is innitiated as a nicedit and filled with data from db here

 function get_edit_content(box_id,page_ref,template_ref)
   {
$(document).ready(function() {

  if(area1) {       
    area1.removeInstance('edit_content');
    area1 = null;
    document.getElementById("edit_content").value="";        
    }
    $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref } )
  .done(function(data) {         
      document.getElementById("edit_content").value=data;          
      document.getElementById("page_ref").value=page_ref;
      document.getElementById("template_ref").value=template_ref;           
      document.getElementById("box_id").value = box_id;                  
      area1 = new nicEditor({fullPanel : true}).panelInstance("edit_content",{hasPanel : true});              
      });  
    });
   }

when I click on the 'Save' button I call this function

$(document).ready(function() {  
  $('.button').click(function() {
     var edit_content = $('#myFrm').find('.nicEdit-main').text();       
     var box_id = $('#myFrm').find("#box_id").val();
     var page_ref = $('#myFrm').find("#page_ref").val();
     var template_ref = $('#myFrm').find("#template_ref").val();
     $.post("update_textarea.php",
      {
       box_id:box_id, page_ref:page_ref, template_ref:template_ref, edit_content:edit_content
      },
     function(data,status){                 
       alert(data);
       UpdateElementOfParent(box_id, page_ref, template_ref)            
       edit_box('hide')
     });
   });
  });

the 'alert(data)' returns the content of the textarea, but with no formatting and a tab space at the beginning of the content

any clues?

Was it helpful?

Solution

What if you try using $.html() instead of $.text() ?

$(document).ready(function() {  
    $('.button').click(function() {
        var edit_content = $('#myFrm').find('.nicEdit-main').html();
        // console.log(edit_content);
        alert(edit_content);
        [...]
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top