[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
|
Nick Boldt wrote:
> Couple thoughts...
>
> 1. Try using fully-formed PHP, not the lazy <?= ?> format.
That didn't make a difference.
> 2. Try wrapping your javascript variable assignment (unless it's an
> integer!) with quotes.
They are integers, but it doesn't matter since I'm just passing them to
a PHP script with AJAX. This actually worked, but I have a new problem:
if (parentValue)
{
<?php echo $function;?>
}
gives me these errors:
Multiple annotations found at this line:
- Syntax error on token "<", invalid Expression
- Syntax error on token "?", invalid Expression
- Syntax error on token ">", FullPostfixExpression expected after this
token
- Syntax error on token "echo", : expected
- syntax error, unexpected 'EOF'
It seems like the Javascript parser has trouble with the PHP inside the
javascript, even though the javascript is in a PHP file.
>
> 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
> }
>
> ?>
I might have to try this instead.
> 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
>