Question

this is my code

 $('#Cancel').click(function() {

        var baseurl     = ' <?php echo $this->strBaseUrl?>';
        var cancel_msg  = " <?php echo Messageclass::setMessage('CAN01')?>";

        var where_to = confirm(cancel_msg);
        if (where_to == true){
            return true;
        }else{
            location.href = "";
        }

    });

but there is an error showing below the variable cancel_msg. the error is

Uncaught SyntaxError: Unexpected token ILLEGAL 

the php logic is working perfectly. if any one know about this please help me

thanks in advance

Was it helpful?

Solution

It really depends on what setMessage outputs, but that error is referring to an illegal character. This could be a newline character but is more likely a double quote:

var cancel_msg = " <?php echo addslashes(Messageclass::setMessage('CAN01'))?>";

also, you could reduce your function to:

return window.confirm(cancel_msg);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top