1

This is my td that wrote with JS:

'<td contenteditable="true" onBlur="saveToDatabase(this,s1,' + d.pid + ')" onClick="showEdit(this);">' + d.s1+ '</td>' +

I want to to send saveToDatabase function value to this AJAX code.

function showEdit(editableObj) {
    $(editableObj).css("background", "#FFF");
}

function saveToDatabase(editableObj,column ,id) {
    $(editableObj).css("background", "#FFF url(loaderIcon.gif) no-repeat right");
    $.ajax({
        url: "saveedit.php",
        type: "POST",
        data: 'column=' + column + '&editval=' + editableObj.innerHTML + '&id=' + id,
        success: function(data) {
            $(editableObj).css("background", "#FDFDFD");
        }
     });
}

But I get an error:

Uncaught ReferenceError: hashie_sod is not defined

what is the problem ?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

0

It sounds like hashie_sod is the value in your d.pid variable. In which case you need to wrap it in quotes when building your HTML string:

'<td contenteditable="true" onBlur="saveToDatabase(this, s1, \'' + d.pid + '\'")" onClick="showEdit(this);">' + d.s1+ '</td>'

Or better yet, use JavaScript to attach your events:

'<td contenteditable="true" class="content-edit-td" data-s1="' + s1 + '" data-pid="' + d.pid + '">' + d.s1+ '</td>'
$('.content-edit-td').on({
    'click': function() {
        $(this).css("background", "#FFF");
    },
    'blur': function() {
        $(this).css("background", "#FFF url(loaderIcon.gif) no-repeat right");
        $.ajax({
            url: "saveedit.php",
            type: "POST",
            data: 'column=' + $(this).data('s1') + '&editval=' + $(this).html() + '&id=' + $(this).data('pid'),
            success: function(data) {
                $(this).css("background", "#FDFDFD");
            }
        });
    }
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339