Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

php and javascript, How does one do this?

7:57 am on Oct 4, 2004 (gmt 0)

New User

10+ Year Member

joined:Dec 1, 2003
votes: 0

Hi there i am currently working on an ecommerce site and i have a problem with the checkout page.

when a customer goes to the checkout page they are shown a rundown of all the necessaries eg(price,shipping,etc) then the click a javascript link saying "pay by Credit Card" which takes them to a secure bank's payment page.

The problem that i have is that i want to pass a few variables thru like price for example and also if possible the customers email address and an invoice number.

How do i attach the JS code to php (i hope i am asking the question so you can all understand it here) so that when the link is clicked the values go thru. I have all the javascript at the top so i know what to call the variables i.e.
sClientID + '&description=' + sDescription + etc. but how do i attach that to the price when the price is being dynamically generated?

This is the Javascript below:

<script language="javascript"><!--
function gotopay(sDescription, sEmail, sUniqueID, iAmount) {
// New Window options
sResize = 'yes';
sToolbar = 'no';
iWidth = 680;
iHeight = 560;
sSite = 'https://banksite';
sClientID = 'clientid=123;
sURL = sSite + '?' + sClientID + '&description=' + sDescription + '&invoice=' + sUniqueID + '&amount=' +
iAmount + '&email=' + sEmail + '&t=1';
window.open(sURL,'','resizable=' + sResize + ',toolbar=' + sToolbar + ',scrollbars=' + sScrollbars + ',width='
+ iWidth +',height=' + iHeight);

And then this is where i believe the order total is being generated

echo $order_total_modules->output();

So how do say to the pop-up that that is the price?

and what do i put next to the pop-up?

<a href="javascript:gotopay()"><img src="popup/bank.gif"></a>

Any help would be much appreciated as this is causing some discomfort to my sleeping habits at the moment!

Thanks in advance and i look forwar to your most generous help.



3:24 pm on Oct 5, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 5, 2002
votes: 0

As far as I know JavaScript is a client site scripting language, whereas php is executed on the server. I think there is no way to transform any variable from one language to the other by a static link.

What you might do is substitue the link by a submit button within a form, generate the input-values (type = hidden) by a javascript writeLn and send the whole form to a php site, which then generates your second window.

The other would be to generate the link itself by writeLN and transform the values as a?-query-string.

But before that I would rather more lean back and think whether you really have to invent the wheel again. There are a number of stable shop systems in either javascript or php available on the net.

Hope this helps a bit


9:52 pm on Oct 5, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
votes: 0

Let me see if I get this right... You want to use a value generated by PHP in your JavaScript?

If so, just echo the value:

<script type="text/javascript">
price = "<?php echo $price;?>";