I have the following function that will show a pop up message, once the user click ok it will navigate the user to the controller called backendBanner and call the function delete_banner.
The link written in html and php looks something like this:
<a href="<?php echo base_url().'backendBanner/delete_banner/'.$banner['banner_path']; ?>">
Code for the button in view to call the function
<td>
<a onclick="return remove_image($(this));" rel="<?php echo $banner['banner_path']; ?>"><input type="button" class="btn btn-danger" value="Delete"></a>
</td>
Code for the function In this function, $banner['banner_path'] is equal to fullpath
<script>
function remove_image(img)
{
if(confirm('<?php echo lang('confirm_remove_image');?>'))
{
var fullpath = img.attr('rel');
alert(fullpath);
redirect(base_url()."backendBanner/delete_banner/"+fullpath);
}
}
</script>
How should I go about bringing the user to the link through the function?
It should be :
window.location="<?php echo base_url().'backendBanner/delete_banner/'.$banner['banner_path']; ?>" + fullpath
The problem in your JS code is that you're using redirect()
. This will not work because redirect()
is a PHP/Codeigniter function, not JS.
Use window.location
instead.
Assuming that the function base_url() it's a valid function created by you...
Try with:
location.href = base_url() + img.attr('rel');
Note: Try to use some templating engine like twig, blade etc.