using JS var in ajax data option?

i want to use a JS var in the dropdownlist selection change ajax data option, but couldn’t work it out.

Always get this error:

PHP Error

Description : Use of undefined constant eml - assumed ‘eml’

[color="#0000FF"]

<script type=“text/javascript”> var eml=’’; </script>[/color]

dropdownlist ajax code:

[color="#0000FF"]

‘ajax’ => array(

    ...


'data'=&gt;&quot;js:{did: &#036;(this).val(),


		exclude: &quot;[color=&quot;#8B0000&quot;]+ eml +[/color]&quot;;  }


	}&quot;,


)

[/color]

The eml value gets modified on other events.

The ajax is working all fine if i remove the eml variable from there & calculate the value within it using function(){ … }.

But its slowing the whole process by running a loop everytime the selection gets change which is completely unnecessary when the value is already there in a JS variable.

Shouldn’t be like that:




'ajax' => array(

...

'data'=>"js:{did: $(this).val(),

exclude: eml; }

}",

)



You got the php error because eml is out of the php string, you should write like:





'ajax' => array(

...

'data'=>"js:{did: $(this).val(),

exclude: \"+ eml +\"; }

}",

)



or





'ajax' => array(

...

'data'=>'js:{did: $(this).val(),

exclude: "+ eml +"; }

}',

)



for receive the javascript code you need. Anyway I think that the correct version is the first one.

Yeah, i got that work!