ReferenceError: event is not defined

Hello, i made this ajax call to approve some lines on my page:

    //calling ajax on click
    <button type="submit" class="btn btn-default btn-sm" id="approveLine" onclick="approveLine('.$row['id'].')"> approve</button>


	function approveLine(val) {
		
		event.preventDefault();

		$.ajax({
			global: false,
			type: 'GET',
			url: '/action.php?action=approveLine&id='+val+'',
			
			success: function (result) {
				console.log(result);
				$('#contenthere').load('/receipt.php?view=edit&id=<?=$id;?>&res=approved');
			},
			error: function (request, status, error) {
				serviceError();
			}
		});
	}

It worked all good on Chrome, IE and Edge until i tried it on mozilla
it returned error : ReferenceError: event is not defined

How can i fix that?

Thanks for comments!

Place the row id in an attribute called data-rowid. That lets you pass the event to the function instead, from where you can then retrieve that id with $(event.target).data("rowid")

1 Like

Yeah that seems did the job :slight_smile: Thanks allot! You saved me a lot of time!

This should work in all browsers?

Yes.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.