noblemfd's avatar

Uncaught SyntaxError: missing ) after argument list

In my Laravel-5.8 project I have:

public function destroy($id)
{

  $goal = AppraisalGoal::findOrFail($id);
  $goal->delete();
  Session::flash('success', 'Appraisal Goal deleted successfully.');
  return redirect()->back();
}

blade

      <button class="btn btn-xs btn-danger" type="submit" onclick="deleteTag({{ $goal->id }}, {{$goal->goal_title }})">
             Delete
      </button>
      <form id="delete-form-{{ $goal->id }}" action="{{ route('appraisal.appraisal_goals.destroy',$goal->id) }}" method="POST" style="display: none;">
             @csrf
             @method('DELETE')
       </form>

During delete, I want to customize the message:

Are you sure you want to delete $goal->goal_title

'goal_title' is a field in the table appraisal_goals. I am expecting some like : Are you sure you want to delete Appraisal2020. Appraisal2020 is one of the data in the field. THat means it is to confirm whether you want to delete the selected field as in $goal->goal_title

<script type="text/javascript">
  function deleteTag(id) {
    var name = $(this).data('goal_title');
    swal({
        title: 'Delete',
        text: "Are you sure you want to delete "+name+"!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: 'No, cancel!',
        confirmButtonClass: 'btn btn-success',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false,
        reverseButtons: true
    }).then((result) => {
        if (result.value) {
            event.preventDefault();
            document.getElementById('delete-form-'+id).submit();
        } else if (
            // Read more about handling dismissals
            result.dismiss === swal.DismissReason.cancel
        ) {
            swal(
                'Cancelled',
                'Your data is safe :)',
                'error'
            )
        }
    })
  }
</script>

When I added the code above, it displays it as I have written it.

Uncaught SyntaxError: missing ) after argument list

Where is error coming from?

What do I do?

Thank you.

0 likes
5 replies
Snapey's avatar

Where is error coming from?

The error usually tells you

Snapey's avatar

related to this?

onclick="deleteTag({{ $goal->id }}, {{$goal->goal_title }})"

You pass two parameters to deleteTag, but you accept only one;

function deleteTag(id)
Sinnbeck's avatar

Did you mean to do this?

function deleteTag(id, name) {
    
    swal({
        title: 'Delete',
        text: "Are you sure you want to delete "+name+"!",
Snapey's avatar
Snapey
Best Answer
Level 122

ok so since goal title is a string, you need to wrap it in quotes


onclick="deleteTag({{ $goal->id }}, '{{$goal->goal_title }}' )">#

But you are still passing two parameters to the function when only one is accepted

1 like

Please or to participate in this conversation.