Forum Moderators: coopster
>> normally you can't mix PHP and javascript
au contraire, you can use php to output the javascript, so ouput the php var into your javascript, no problem.
If you are using external js files you might run into a problem but if it is located in a page that is parsed by php then it works the same as outputting any other var.
<script language="JavaScript" src="http://lapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=gxumm%blahblahblahblahblah=1&query=KEYWORD&width=570">
</script>
It is easy to hardcode whatever keyword you want, but I want that value to be a variable value related to the page topic (like the name of a movie or something, different on each page)
I tried replacing KEYWORD with
<?php echo $KEYWORD_HERE;?>
but it just comes out as a blank space.
How can you get a PHP variable value inserted into the javascript code, since one is happening client side and one server side?
>> since one is happening client side and one server side
but remember that the page is built on the server before it is ever sent to the client
this will work in a page that is php parsed
<?
$mykeyword = 'widgets';
?>
<script language="JavaScript" src="http://lapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=gxumm%blahblahblahblahblah=1&query=<?php echo $mykeyword;?>&width=570">
</script>
I've tested putting in the echo line just before this javascript, and the variable text IS there and prints, but as soon as it hits the javascript output it has been lost.
Any other ideas?