ReferenceError: event is not defined

jquery

#1

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!


#2

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")


#3

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

This should work in all browsers?


#4

Yes.


closed #5

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