homepage Welcome to WebmasterWorld Guest from 54.237.184.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
php and javascript, How does one do this?
Oslo2004




msg:1480269
 7:57 am on Oct 4, 2004 (gmt 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';
sScrollbars='yes';
iWidth = 680;
iHeight = 560;
sSite = 'https://banksite';
sClientID = 'clientid=123;
sURL = sSite + '?' + sClientID + '&description=' + sDescription + '&invoice=' + sUniqueID + '&amount=' +
iAmount + '&email=' + sEmail + '&t=1';
//alert(sURL);
window.open(sURL,'','resizable=' + sResize + ',toolbar=' + sToolbar + ',scrollbars=' + sScrollbars + ',width='
+ iWidth +',height=' + iHeight);
}//--></script>

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

<?php
if (MODULE_ORDER_TOTAL_INSTALLED) {
$order_total_modules->process();
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.

Thankyou

Enrico

 

Oliver Henniges




msg:1480270
 3:24 pm on Oct 5, 2004 (gmt 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

Oliver

DrDoc




msg:1480271
 9:52 pm on Oct 5, 2004 (gmt 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;?>";
alert(price);
</script>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved