Skip to content Skip to sidebar Skip to footer

Echo PHP Variable Inside JQuery SwitchCase?

I have a jQuery script that I am including on a PHP page that takes mt content and creates facebook/myspace share links. I am having trouble echoing PHP code inside of the swith c

Solution 1:

Option 1. In your file.php:

<script type="text/javascript">
   var varName = "<?php echo '1'; ?>"; // global
</script>
<script type="text/javascript" src="myscript.js"></script>

Option 2. create a PHP file that returns the javascript content type externalphp


Solution 2:

By default, apache with mod_php doesn't parse files with a .js extension. That behaviour can be modified in the apache config files.

Alternatively (this solution will be less heavy on the parser because it wont parse all .js files), give the javascript files you need to parse a .php extension


Solution 3:

Have you tried putting it in a variable instead ?

var varName = '<?php echo "1"; ?>' ; or var varName = "<?php echo '1'; ?>";

and then use that variable in your javascript code.

You may need to use praseInt(...) to get a number through.


Post a Comment for "Echo PHP Variable Inside JQuery SwitchCase?"