[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.pdt] Re: PHP inside of Javascript in a .php file

Couple thoughts...

1. Try using fully-formed PHP, not the lazy <?= ?> format.
2. Try wrapping your javascript variable assignment (unless it's an integer!) with quotes.


Thus:

 <?php

 function SomeFunction()
 {

 ?>
 		<script type="text/javascript">
 		parentValue = '<?php print $parentValue; ?>';
 		</script>
 		<?
 }

 ?>

Or, better:

 <?php

 function SomeFunction()
 {
   print<<<EOHTML
<script type="text/javascript">
  parentValue = '${parentValue}';
</script>
EOHTML; // must be flushed to left margin
 }

 ?>


Micah wrote:
I have Javascript code that I output inside of a PHP file, but put
variables inside the javascript block.  I am getting a weird error:

<?php

function SomeFunction()
{

?>
		<script type="text/javascript">
		parentValue = <?=$parentValue?>;
		</script>
		<?
}

?>

I get an error over the '<?' of the '<?=' expresssion in the javascript
block saying: Syntax error on tokens, PostfixExpression expected instead

Anyone know why this is?

Thanks,
Micah

-- Nick Boldt :: http://wiki.eclipse.org/User:Nickb