Q:

Trying to de-increment only a positive number

The form code:
    <td><form action="cart.php" method="get">
 <input type="button" onclick="buttonSubtract1()" name="subtract1" value="-
"/>
 <input type="text" size="4" id="qty1" name="quantity1" value="0"/>
 <input type="button" onclick="buttonAdd1()" name="add1" value="+"/>
 <input type="submit" name="product1" value="Add"/>

The javascript:
var i = 0;
var qty1 =  document.getElementById('qty1').value;
function buttonAdd1() {
document.getElementById('qty1').value = ++i;
}
function buttonSubtract1() {
if (qty1 > 0) {
document.getElementById('qty1').value = --i;}
}

I changed the code to increment and de-increment using javascript which worked fine so I tried to make it so that de-incrementation only works if the number is positive but now incrementing is working fine but it is not allowing de-incrementation of any number. Why is this?

A:

You just have to put the var qty1 =  document.getElementById('qty1').value; into the subtract function like this:
var i = 0;
function buttonAdd1() {      
   document.getElementById('qty1').value = ++i;
}
function buttonSubtract1() {
   var qty1 =  document.getElementById('qty1').value;
   if (qty1 > 0) {
     document.getElementById('qty1').value = --i;}
   }
}

In your Example, you just write the First Value (0) into the Window objekt.
It stays zero until you change it in the window object again.
But if you ask the Value everytime the function is called, you get always the newest number.
Fiddle:
http://jsfiddle.net/9wHU9/

