Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » PHP inside of Javascript in a .php file
PHP inside of Javascript in a .php file [message #90689] Fri, 16 January 2009 02:14 Go to next message
Eclipse UserFriend
Originally posted by: micahjg26.netscape.net

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
Re: PHP inside of Javascript in a .php file [message #90737 is a reply to message #90689] Fri, 16 January 2009 06:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nickboldt+eclipse+newsgroup.gmail.com

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
Re: PHP inside of Javascript in a .php file [message #90752 is a reply to message #90737] Fri, 16 January 2009 09:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: micahjg26.netscape.net

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
>
Re: PHP inside of Javascript in a .php file [message #90782 is a reply to message #90752] Fri, 16 January 2009 16:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: nickboldt+eclipse+newsgroup.gmail.com

Micah wrote:
> if (parentValue)
> {
> <?php echo $function;?>
> }

What is the value of $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.

You might want to open a bug against PDT (or maybe this is a DLTK
issue?) explaining what you've tried and what workarounds (if any) work
to clear the reported errors.

Sounds like there are parser usecases not yet implemented.

Have you tried doing your javascript in a separate file so that it can
be parsed w/ a JS editor, rather than a PHP editor?

--
Nick Boldt :: http://wiki.eclipse.org/User:Nickb
Re: PHP inside of Javascript in a .php file [message #90843 is a reply to message #90782] Fri, 16 January 2009 18:02 Go to previous message
Eclipse UserFriend
Originally posted by: micahjg26.netscape.net

Nick Boldt wrote:
>
>
> Micah wrote:
>> if (parentValue)
>> {
>> <?php echo $function;?>
>> }
>
> What is the value of $function?

The name of a xajax function. This is while editing, not running that I
get the error.

>
>> 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.
>
> You might want to open a bug against PDT (or maybe this is a DLTK
> issue?) explaining what you've tried and what workarounds (if any) work
> to clear the reported errors.

I'll have to do that. I just wanted to make sure that I wasn't missing
a config setting before filing a bug.

>
> Sounds like there are parser usecases not yet implemented.
>
> Have you tried doing your javascript in a separate file so that it can
> be parsed w/ a JS editor, rather than a PHP editor?
>

I have pure Javascript functions in a separate file, but it happens to
be that 65% of this function is generated from PHP variables, so I am
outputting it inline.

Thanks,
Micah
Previous Topic:Enabling javascript on a project
Next Topic:How to keep an all-in-one up to date?
Goto Forum:
  


Current Time: Sat Apr 20 03:55:33 GMT 2024

Powered by FUDForum. Page generated in 0.04384 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top