Danvin Lee Qicheng Danvin Lee Qicheng - 1 year ago 114
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:

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 ;

$('#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 Source

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>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download