Looping through Array fields

A

Anonymous

Guest
Hello all.

here is what i want to do.
on the first page they user selects a quantity of a product.

on this page (the one with the problem)
he cannot select more accessories than the product quantity


i have the following a
Code:
echo "   <input type=hidden name='qty' value='".$qty."' size=2>";
echo "   <input type=text name='qty_".$x."' onfocus='check()' value=0 size=2>";
echo "   <input type=hidden name=total value='$x'>\n";
where $x is the number of accessories for that selected product

here is the javascript
when you check the document.all.qty_+x.value it says NaN
Code:
   function check() {
      var tot = 0;
      for (var x = 0; x <= document.all.total.value; x++) {
         tot = tot + (document.all.qty_+x.value);
      } // end for
      if (tot > document.all.qty.value) {
         alert('you have selected more accessories  than you have products');
      } // end if
   } // end function

When i do this
Code:
      alert(document.all.qty_0.value);
      alert(document.all.qty_1.value);
it works

So my question is
how can i get document.all.qty_+x.value to return a value ??
 
just for interest sake

eval()

was what helped me out.
 
Back
Top