bettor suggested that, and I thought I tried it. I tried it again and it worked this time. I must have done something wrong the first time. However, this method ignores the new line characters. It just prints them as part of the confirm. The jQuery in the source is very similar, so I don’t understand why. Any ideas?
"onclick"=>"if (!confirm('Are you sure?\\r\\nDrafts are permanently deleted and are not recoverable.')){return}",
produces:
jQuery('#yt0').live('click',function(){if (!confirm('Are you sure?\r\nDrafts are permanently deleted and are not recoverable.')){return};jQuery.ajax({'type':'POST','data':{'algo_id':'4','action':'delete'},'success':algoDelete,'url':'/test/algo/ajaxpost','cache':false});return false;});
and
'confirm'=>'Are you sure?\r\nDrafts are permanently deleted and are not recoverable.'
produces:
jQuery('#yt0').live('click',function(){if(confirm('Are you sure?\\r\\nDrafts are permanently deleted and are not recoverable.')) {jQuery.ajax({'type':'POST','data':{'algo_id':'4','action':'delete'},'success':algoDelete,'url':'/test/algo/ajaxpost','cache':false});return false;} else return false;});
Only having single backslashes in the code still results in double in the source - which is what I suspect is causing the problem. Any suggestions?
Yeah… what is the difference between single and doulbe quote is still a mistery to me… I know that when one doesn.t work I can always bet on the other one…
The problem above is, that you have quoted javascript strings inside a PHP string. This can be confusing. That’s why it’s even more important that at least the PHP side is well understood.
Double quoted string - PHP will interpret more escape sequences for special characters and expand PHP variable names
Single quoted string - only a single quote can be escaped, escaping all other characters like \n will print the backslash too, does not expand PHP variable names
Sorry for posting on an old thread but this is the best one I found for this topic. Here is the code I came up with for my app:
echo CHtml::ajaxLink("Refund Tip",array("cfgCreditTransactions/refundTip", "id" => $trans->objid,"refresh"=>0),array(),array('confirm'=>'Are you sure you want to refund this tip?'))
Which only has 1 issue, the confirmation dialog will show up many times. By that I mean you may have to click somewhere between 4 and 20 times to get the dialog to go away. Anyone else have this issue? Or see what would cause this in my code? I put this on a /site/page/about to test and it does the same thing there…TIA