0

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.

nnnnnn
  • 147,572
  • 30
  • 200
  • 241
Danvin Lee Qicheng
  • 57
  • 1
  • 2
  • 12

3 Answers3

0

the onClick call '+obj.leaveRecords[aa].idleave +' contains the mistake. You don't need to wrap it with + and '

Try this instead: <a> onClick="editstatus(obj.leaveRecords[aa].idleave)" </a>

0

The error is probably in this part of your code:

onClick="editstatus('+obj.leaveRecords[aa].idleave +')"

Try replacing it with this one:

onClick="editstatus(obj.leaveRecords[aa].idleave)"

You don't need to use '+ inside the parameters of the function.

0

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>';
user94559
  • 59,196
  • 6
  • 103
  • 103