如何回显在php中保存确认的javascript函数

need some help on calling javascript function inside php basically inside my controller codeigniter. the script was writtten on the view page. Now, i'm calling in inside my controller.

View page:

     function confirmation() {
    var txt;
    var r = confirm("Press a button!");
    if (r == true) {
        txt = "You pressed OK!";
    } else {
        txt = "You pressed Cancel!";
    }
    document.getElementById("demo").innerHTML = txt;
}

Controller:

echo 'confirmation()';

If understand this correctly you want your function to execute at a specific point of your view action.

In that case just print the javascript code exactly where you want it to show up in your view action.

<script type="text/javascript">
  confirmation();
</script>

If you can't echo that, then use require_once() or include_once() to include the file which may be a .phtml or simple .js file.

</div>