Question

After adding my code, other javascript functions within the .js file stopped working too. So I'm thinking it might be a problem with the code. I'm also trying to implement a codeigniter php code within the .js file.

This is the added function in .js file:

function confirmDelete(del, id){
    var r=confirm("Confirm delete?");
    if (r==true){
        <?php redirect(base_url('home/delete/')+del+"/"+id, 'refresh'); ?>
    }
    else{
        <?php redirect(current_url(), 'refresh'); ?>
    }
};

This is how I used it in the view file:

<a href="" onclick="confirmDelete('event', <?php echo $record['id']; ?>);">X</a>

No correct solution

OTHER TIPS

Is the .js file generated by php? If not, you can't use PHP code there. Try this to confirm the JavaScript function is working fine:

function confirmDelete(del, id){
    var r=confirm("Confirm delete?");
    if (r==true){
        alert('deleted!');
    }
    else{
        alert('not deleted!');
    }
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top