Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Yahoo to Paypal conversion - JS Newbie (1 of 2 posts)

How do I convert from Yahoo to Paypal Shopping cart

2:18 pm on Apr 16, 2003 (gmt 0)

10+ Year Member

Below are 2 scripts.\REVISION: Scripts are split into two posts, this one (the configurator) and the next one [webmasterworld.com] (the paypal script)\ One is an edited snipet of a computer configurator.

Basically you select the parts from a list of options (cpu, memory, etc) and it shows how much that item is, and adds the total (total2). It then sends that value to a yahoo shopping cart. However, I need to use Paypal (and eventually something different when I can afford it).

I am fairly illiterate when it comes to programming, and as of about 2 weeks ago I didnt know the first thing about javascript...Im trying to learn among doing 5 million other things, but I really need help. I found another page that has a paypal cart Id like to use...they dont have a configurator that adds values of an assembled custom system, instead, you add individual parts to the basket.

I would like to be able to configure a system then add that system (labor, parts, shipping and all) and send that to paypal. Obviously Id also need to be sent an email telling me what options were selected so that I can begin to build it. I have both scripts below. I have added my stream-of-consciousness thoughts (preceding each part of the script) as I went through the pages seeing what parts were pertinent to this forum.

Also the segments of the first script (the configurator that Id like to use) are seperated by //#A (eg //1A) and the second script (the paypal shopping cart) is broken up by //#B. I hope its in a format thats readable, as this is the first time Ive sought help on programming advice. I am a hardware guy myself. If anything, I hope my comments throughout helps in seeing the thought process of a somewhat newbie (I used to love BASIC, but I dont see too many Commodore's these days). Thanks for the help.

<script language="JavaScript">

guessing the following rounds numbers to whole numbers

function showpos(value){
var str = "" + Math.round(value*100);
var len = str.length;
return (str=="0")?"":(str.substring(0,len-2)+"."+str.substring(len-2,len));

I think you change the 0 * 1 to say 20 * 1 (or was it 0 * 20?) to jack prices up $20 (can this be changed to a percentage?)

function get_total(){
//edit here for starting price
var tmp = 0 * 1;

//do not edit

this comment was in the script already (do not edit and edit here for starting price) - I guess this adds the variables from the various options in each catagory. If I were to change a value here I have to change name="hd2" to name="hd3" for example, right? Curious what var type_array=type.split(","); means - oh wait, this sets the variable names, the next part adds them...still dont know what the var type_array... is all about though.

<note: line breaks added here to prevent side scrolling>

var type = "cas,cpu,motherboard,memory,temp,flashmedia,cpufan,hd1,hd2,video_card,dvd,cdr,monitor,
var type_array = type.split(",");

ok, this adds the options...I see the type.array and type.split but it isnt registering to me exactly how it takes the above variables and adds them as they change

for(loop = 0; loop < type_array.length; loop++){
var name = eval('document.calculate.' + type_array[loop] + '.value.split(",")');
name[0] = name[0] * 1;
tmp = tmp + name[0];


Or does it add it here...now Im confused...

document.calculate.total1.value = "(+" + showpos(tmp) + ")";
document.calculate.total2.value = "$" + showpos(tmp);


I see this is for a button that you can click to have a popup window with more product specs. Now, to have a page called cpu.htm pop up I think I add the line <a class="morelink" href="javascript:MoreInfo('cpu');"><img src="qmark.gif" border="0" width="20" height="20"></a> where I want that link to be

function MoreInfo(type){
var type_index;
var index_url;

type_index = eval('document.calculate.' + type + '.selectedIndex');
index_url = 'spec/' + type + type_index + '.htm';



This is what I want changed to PayPal...it is right below the above script. Instead of the value of total1 or total2 (whichever it uses) going to a yahoo cart, Id like it to go to a PayPal cart. Also, what is the <form class="xgear"? what does it refer to? Is this pertinent to the form as a whole or to the yahoo cart (or to shopping carts in general)?:

<form class="xgear" style="FONT-SIZE: 8pt" name="calculate" action="http://order.store.yahoo.com/cgi-bin/wg-order?businessnamedeleted+amdcon" method="post">

OK, this is a snipet from one item I see that xgear class again so I think it relates to the form, and when the option changes, it updates the value of "hd2" in the function "get_total" ...cool, just figured that out!

<td align="left" width="150">
<p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
<font face="Arial" size="2"><b>Hard Drive 2</b></font></td>
<td width="640"><font face="arial, helvetica" size="2">
<select class="xgear" onchange="get_total();" size="1" name="hd2">
<option value="0,---Optional---" selected>---Optional---</option>
<option value="87,Item 1 [+$87]">Item 1 [+$87]</option>
<option value="88,Item 2 [+$88]">Item 2 [+$88]</option>

now what confuses me is that there seems to be a "total1" and "total2", but hey are the same...One is at the top of the table and the other at the bottom but at the top (//1A) was the following :

document.calculate.total1.value = "(+" + showpos(tmp) + ")";
document.calculate.total2.value = "$" + showpos(tmp);

which I thought was adding the two values, but maybe not...anyways, I guess below it takes the value in "total2" and uses it for the value that is added to the yahoo cart, but again Id like it go to a PayPal cart.

<td width="150" bgColor="#ff6600" height="22">&nbsp;</td>
<td width="640" height="22">
<p align="left"><b>Subtotal: </b>
<input style="COLOR: #0000ff; FONT-FAMILY: Arial" readOnly size="10" value="$499.00" name="total2"></td> <---Default value (name="total2")
<td width="150" bgColor="#ffffff" height="90">&nbsp;</td>
<td width="640" height="90">
<p align="center">&nbsp; </p>
<p align="center">
<input type="submit" value="Add To Shopping Cart" name="submit">&nbsp;
<input type="reset" value="Reset"> </p>
<p align="center">&nbsp;</td>


<input type="hidden" value="http://www.businessnamedeleted.com/amdcon.html" name=".autodone">
<input type="hidden" value="buyxg" name="vwcatalog">
<input type="hidden" value="AMDCON" name="vwitem">

The other script is in the next post (the paypal cart Id like to use) since apparently the two combined are too long for a single post.

[edited by: tedster at 7:18 pm (utc) on April 16, 2003]

7:41 am on Apr 19, 2003 (gmt 0)

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

This is much more code than we normally want to see in a post, but given the situation and the fact that others may wrestle with this conversion, here it is. For a discussion of our approach to Posting Code, see this thread [webmasterworld.com].

pctechguy's post about converting from Yahoo to PayPal continues here:


Featured Threads

Hot Threads This Week

Hot Threads This Month