I have done the following.
<td class="text-center"><a href="#" title="" id="signal_<?=$rs['signal_id']?>" addEventListener('click','editSignal(this)') data-toggle="modal" data-target="#send_distress_modal"><i class="fa fa-edit"></i></a></td>
<td class="text-center"><a href="#" title="" id="signal_<?=$rs['signal_id']?>" onclick="deleteSignal(this);"><i class="fa fa-trash"></i></a></td>
I had it done using onclick but want to do the same using addeventlistener('click,'anyFunction'). Because when I use onclick it gives the folowing error;
VM7707 log:330 Uncaught ReferenceError: editSignal is not defined
at HTMLAnchorElement.onclick (VM7707 log:330)
These are the functions below there is some problem with both they give error when clicked. Can't figure out what is the problem.
<script type="text/javascript">
function editSignal(obj) {
// alert(obj.id);
var obj_id = obj.id;
var id = obj_id.split("_");
console.log(id);
let _token = $('meta[name="csrf-token"]').attr('content');
$.ajax({
url: 'send_distress_signal',
type: 'POST',
dataType: 'json',
data: {edit_signal_id: id[1],
// _token: _token
}},
})
.done(function(result) {
console.log(result);
$('#description').val(result['description']);
$('#resType').val(result['resource_type']);
$('#res').val(result['resource']);
$('#resource_hidden').val(result['resource']);
$('#location').val(result['location']);
$('#edit_flag_signal').val(result['signal_id']);
populateResource();
})
.fail(function() {
alert("error");
});
}
function deleteSignal(obj) {
// alert(obj.id);
var obj_id = obj.id;
var id = obj_id.split("_");
$.ajax({
url: 'includes/sendDistress_action.php',
type: 'POST',
data: {del_signal_id: id[1]},
})
.done(function(result) {
if(result=="Success"){
location.reload();
}else{
alert("Some error occured");
}
})
.fail(function() {
alert("error");
});
}
$('#distress_btn').on('click', function(event) {
event.preventDefault();
/* Act on the event */
$('#description').val('');
$('#resType').val('');
$('#res').val('');
$('#resource_hidden').val('');
$('#location').val('');
$('#edit_flag_signal').val('0');
});
Thanks.