You don't need to mix HTML code and JavaScript code inside of PHP script. Instead of that you can place <script>
element
<script type="text/javascript" src="theURL.js"></script>
in the PHP script. The JavaScript code you can place in the .JS file.
UPDATED: You can make of cause a mix between inline JavaScript code where you set some global variables and the JS file where you use the variables:
in PHP code you use
<script type="text/javascript">
var MYGLOBALSETTINGS = {
cnames: ["Column 1", "Column 2", ...],
cmodel: [{...}, {...}...],
url: "myUrl"
};
</script>
<script type="text/javascript" src="my.js"></script>
and in my.js
you just use MYGLOBALSETTINGS.cnames
and MYGLOBALSETTINGS.cmodel
$("#imports_grid").jqGrid({
// jqGrid settings
url: MYGLOBALSETTINGS.url,
datatype: "json",
colNames: MYGLOBALSETTINGS.cnames,
colModel: MYGLOBALSETTINGS.cmodel,
onSelectRow: function() {
// Code
},
});