Danvin Lee Qicheng Danvin Lee Qicheng - 3 months ago 9
Javascript Question

Parse error javascript code

Hi all i am having an error below error cause by the last part , could anyone point out whats wrong

Error Prompt:

Parse error: syntax error, unexpected '[', expecting ',' or ';
'

Error at this line:

<a> onClick="editstatus('+obj.leaveRecords[aa].idleave +')" </a>


Full Code:

$.ajax({
type: "POST",
url: url,
data: {'wid' : wid},
success: function(data)
{
var obj = jQuery.parseJSON(data);

$("#WorkerName").text(name + " Leave Application");

$.each (obj.leaveType, function (bb) {

$( "#tbody-"+obj.leaveType[bb].idleavetype ).empty();

$.each (obj.leaveRecords, function (aa) {

if(obj.leaveType[bb].idleavetype == obj.leaveRecords[aa].idleavetype)
{
var leaveid = obj.leaveRecords[aa].idleave ;
console.log(leaveid);

$('#tbody-'+obj.leaveType[bb].idleavetype).append('<tr><td>'+obj.leaveRecords[aa].reason+'</td><td>'+obj.leaveRecords[aa].startleaveDate+'</td><td>'+obj.leaveRecords[aa].endleaveDate+'</td><td>'+obj.leaveRecords[aa].nameStatus+'</td><td>'+obj.leaveRecords[aa].name+'</td><td>'+obj.leaveRecords[aa].ApproveOn+'</td><?php if($groupid == 3){ echo '<td> <a> onClick="editstatus('+obj.leaveRecords[aa].idleave +')" </a></td>'; }?></tr>');
}
});
});
}
});


Thanks in advance.

Answer

The echo in your PHP needs to escape the inner single quotes:

echo '<td><a class="btn btn-warning form-group" data-toggle="modal" data-target="#arform" onClick="editstatus(\' + obj.leaveRecords[aa].idleave + \')" >Change Status</a></td>';