Forum Moderators: coopster

Message Too Old, No Replies

adding php variable into Ebay javascript?

adding php variable into Ebay javascript?

         

galtemail

4:07 pm on Jul 11, 2005 (gmt 0)

10+ Year Member



I assume someone else here must be using CJ Ebay auction listing code on their site. I know you can manually adjust the query topic to list whatever you want, but how can you insert a PHP variable into the query? The Ebay code is a long javascript SRC link, and normally you can't mix PHP and javascript, but there must be some way to feed a variable value into that SCRIPT code? Someone done this?

jatar_k

4:32 pm on Jul 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld galtemail,

>> 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.

galtemail

8:23 pm on Jul 11, 2005 (gmt 0)

10+ Year Member




Here is a sample of what I am talking about. If you want to display an Ebay table with listings for subject=KEYWORD you have code that looks like this on your page:

<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?

jatar_k

8:29 pm on Jul 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think your variable isn't being set there

>> 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>

galtemail

11:34 pm on Jul 11, 2005 (gmt 0)

10+ Year Member



I tried that - doesn't work (a blank space appears in the source HTML when you view it, as if it skips the <? ..?> entirely).

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?