Hello,

I am attempting to get a pre-existing javascript to output its data to a paypal shopping cart.

The script asks for two values - and then spits out a USD value and an estimated time of completion. I need the USD value to be sent to paypal through their e-commerce package. I have set up quite a few static "add to cart" buttons through paypal already. It has gone very well, but I cannot manage to get this dynamic output to function properly.

So, I'll go ahead and post the javascript bit here.

Code:
function Item(level,time,price) {
        this.level    = level;
        this.time    = time;
        this.price    = price;
    }
    //?????
    var ItemArr = new Array();

    var cur;
    cur = new Item(1, 1, 5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(2, 1, 3.18);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(3, 1, 1.18);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(4, 1, 0.58);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(5, 1, 0.68);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(6, 1, 0.48);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(7, 1, 0.38);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(8, 1, 0.6);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(9, 1, 0.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(10, 1, 0.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(11, 1, 0.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(12, 1, 0.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(13, 1, 0.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(14, 1, 0.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(15, 1, 0.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(16, 1, 1.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(17, 1, 1.6);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(18, 2, 1.6);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(19, 2.5, 1);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(20, 2.5, 1);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(21, 3, 1);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(22, 3, 1.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(23, 3.5, 1.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(24, 4, 2);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(25, 4, 2);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(26, 4.5, 2);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(27, 4.5, 2.2);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(28, 4.5, 2.2);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(29, 6, 3.1);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(30, 6, 3.1);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(31, 6.5, 3.1);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(32, 6.5, 3.1);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(33, 6.5, 3);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(34, 7, 3);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(35, 7, 3);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(36, 7.5, 3);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(37, 7.5, 3);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(38, 7.5, 3);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(39, 8, 3.4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(40, 8, 3.4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(41, 8.5, 3.4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(42, 8.5, 3.4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(43, 9, 3.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(44, 9, 3.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(45, 10, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(46, 10, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(47, 10, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(48, 11, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(49, 11, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(50, 11, 4.22);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(51, 11, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(52, 11.5, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(53, 10.5, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(54, 10, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(55, 10, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(56, 10, 4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(57, 10, 4.4);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(58, 10, 4.19);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(59, 10, 5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(60, 15, 5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(61, 20, 10.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(62, 22, 10.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(63, 24, 11);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(64, 24, 11);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(65, 25, 11.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(66, 25, 11.9);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(67, 25, 12);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(68, 25, 12.5);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(69, 25, 12.9789);
    ItemArr = ItemArr.concat(cur);
    
    cur = new Item(70, 25, 12.999878);
    ItemArr = ItemArr.concat(cur);
    


    //????
    function doCacl(form)
    {
        //????????
        var beginlevel    = form.beginlevel.value;
        var endlevel    = form.endlevel.value;
        //???????????
        if ((beginlevel == "") | (endlevel == "")) {alert("please enter your level");return false;}
        //??????????????
        if (beginlevel * 1 > endlevel * 1){alert("please enter your level");return false;}
        if ( endlevel * 1 > 70 ){alert("please enter your real level");return false;}
        
        if (( endlevel * 1 < 11 ) | (beginlevel * 1 < 1 ))
        {
        alert("Please choose a correct level range");  
        document.thisformonly.price.value ="";
        document.thisformonly.totaltime.value ="";  
        return false;
        }
        //??????
        var price = 0;
        var totaltime = 0;
        //????
        for (var i=0;i<ItemArr.length;i++)
        {
            if ((ItemArr[i].level * 1 > beginlevel * 1 )&(ItemArr[i].level * 1 <= endlevel * 1))
            {
                price        = price + ItemArr[i].price;
                totaltime    = totaltime + ItemArr[i].time;
            }

            if (ItemArr[i].level * 1 > endlevel * 1){i=ItemArr.length;}
        }
        if ( price < 1 ){alert("Please choose a correct level range");return false;}
        if ( totaltime < 24 ){alert("Please choose a correct level range");return false;}
        if (price>=100)
        {
        form.price.value        =  parseFloat(price).toFixed(2);
        form.score.value        =  Math.round(parseFloat(price).toFixed(2)*0.1);
        }
        if(price<100)
        {
        form.price.value        =  parseFloat(price).toFixed(2);
        form.score.value        =  Math.round(price*0.1);
        }
        form.totaltime.value    = totaltime;
        
    }
\
Here is an example of one of the paypal "add to cart" buttons, which I'm sure you guys have seen plenty of around here.

Code:
<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Order Now!','','images/order_ordernow_rollover_09.jpg',1)"><div align="right"><form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="image" src="http://www.platinum-leveling.com/images/addtocart.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="Payment@platinum-leveling.com">
<input type="hidden" name="item_name" value="Custom Power Leveling">
<input type="hidden" name="item_number" value="10">
<input type="hidden" name="amount" value="140.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.platinum-leveling.com/contact/thankyou.php">
<input type="hidden" name="logo_custom" value="http://www.platinum-leveling.com/images/viewcart.gif">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-ShopCartBF">
</form></div></a>

I essentially want
Code:
price        = price + ItemArr[i].price;
(Or atleast, the "price" part - whatever that would be) in my javascript to replace "140.00" in my paypal button code.
Code:
<input type="hidden" name="amount" value="140.00">
That way, whenever someone enters their values and gets a quote, it automatically adds that USD value to their paypal cart.


Here is a link to the page with the javascript forms working.

http://platinum-leveling.com/order.html

As you can see, it is under construction. I removed the "add to cart" button, as to the effect that it doesn't yet work.

I have search these forums, among others, and have found numerous fixes for similar problems, but they have all been issues with a small number of specific products and values. I have way too many variables to write them all out and assign a value to each. Also, you can see within the javascript, that there are a few rules. So, if you're trying to test the script on my page to see how it works, try "5" as the starting level and "60" as the finish level.

Any suggestions? I always look forward to learning something new.

Thank you for your time!