goose
goose

Reputation: 2652

Trouble writing php variables into javascript

 'success'=>'js: function(data) {
        $("#addToListDialog$model->product_id").dialog().dialog("close");}'

I'm trying to write the above piece of javascript, but can't get the right combination of curly brackets a single/double quotes in order to resolve the PHP variable. How should I be writing this?

Upvotes: 1

Views: 175

Answers (2)

Kevin Somers-Higgins
Kevin Somers-Higgins

Reputation: 985

Your PHP string must be in double quotations.

This should do the trick:

'success'=>"js: function(data) {
        $(\"#addToListDialog{$model->product_id}\").dialog().dialog(\"close\");}"

Upvotes: 1

MarZab
MarZab

Reputation: 2623

A cleaner way:

'success'=>'js: function(data) {
        $("#addToListDialog'.$model->product_id.'").dialog().dialog("close");}'

Upvotes: 3

Related Questions