This project has moved and is read-only. For the latest updates, please go here.

Escaping Characters in Safari

May 20, 2013 at 7:19 PM
Edited May 20, 2013 at 7:35 PM
I have a need to populate a rich text field in a list. I can get it to work in IE with the code below no problem, but when I run tests on the same page in Safari, it doesn't write to the list.

To back up for a moment, what I'm doing is saving a bulleted list to a SharePoint list. I create the basic UL tags in a variable and then iterate over instances of text areas that the user populates in a custom modal and build each LI based on how many textarea's they populate.
function MLTSubmit(){
    var reportData = "<ul></ul>";
    var reportDate = $("#MLTmonths option:selected").text();
    var reportDept = $("#MLTDept").val();
    var reportYear = $("#MLTyear").val();

    $("#MLTTextAreaGroup .MLTTextAreaWrap textarea").each(function(){
        var dataWithoutBullet = $(this).text().substring(1);
        reportData = $("<div />").html(reportData).find("ul").append("<li>"+dataWithoutBullet+"</li>").end().html();

    // escape characters
    reportData = reportData.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;');

    if(reportDept == "Select Department"){alert("Please choose a department.");}
    else {
                operation: "UpdateListItems",
                async: false,
                batchCmd: "New",
                listName: "MLT Reporting",
                valuepairs: [["Title", "MLT Report Data"], ["Author0", thisUserName], ["ReportDate", reportDate], ["Data", reportData], ["Department", reportDept], ["Year", reportYear]],
            completefunc: function(xData, Status) {
                alert("Thank you.");
I believe the problem is in the regex character replacing but any ideas are appreciated.