-2

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

Matt
  • 5,315
  • 1
  • 30
  • 57
deepu sankar
  • 4,335
  • 3
  • 26
  • 37
  • 1
    Possible duplicate: http://stackoverflow.com/questions/12719859/syntaxerror-unexpected-token-illegal – Matt Mar 09 '13 at 04:10
  • 3
    What does `Messageclass::setMessage('CAN01')` return? Perhaps something containing a quotation mark? Also, don’t write `== true`. It’s redundant. – Ry- Mar 09 '13 at 04:11
  • 1
    what is being outputted by Messageclass::setMessage('CAN01')? Anything with double quotes? – MattDiamant Mar 09 '13 at 04:11

1 Answers1

0

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);

Rob M.
  • 35,491
  • 6
  • 51
  • 50
  • Why specify `window`, out of curiosity? Also, there’s still the `location.href = "";` to consider… – Ry- Mar 09 '13 at 04:41
  • because old habits die hard, I only seem to do that with alert, prompt and confirm. Anyway, you are right about the `location.href = ""` part. – Rob M. Mar 09 '13 at 04:46