Javascript - If not in array then add - if in array then update qty
<p>Below is my code for a simple shopping cart, the only problem is the items from the first box work fine, however the second box does not.</p>

<p><a href="http://itsuite.it.brighton.ac.uk/ols11/cart/" rel="nofollow">http://itsuite.it.brighton.ac.uk/ols11/cart</a> - add the "bumblebee" item, and then repeat and it counts correctly. Now try the second drop down a few times.</p>

<p>Javascript:</p>

<pre><code>var ids = []
var names = []
var qtys = []
var prices = []
var total = []


function newcart (id, desc, qty, price)
{
    var lengthofid = ids.length
    var i = 0
    while (i &lt; lengthofid)
    {
        if (id == ids[i])
        {
            qtys[i] = parseInt(qtys[i]) + parseInt(qty)
            prices[i] = parseInt(prices[i]) + parseInt(price)
            i = lengthofid + 1;
        }else{
            ids.push(id)
            names.push(desc)
            qtys.push(qty)
            prices.push(price)
        }
        i++

    }
    if ( i == 0 )
    {
        ids.push(id)
        names.push(desc)
        qtys.push(qty)
        prices.push(price)
    }
    alert(names)
    alert(qtys)
}
</code></pre>

<hr>
