Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

Looping through Array fields

Javascript coding ..

Moderators: macek, egami, gesf

Looping through Array fields

Postby relicviper » Wed Mar 30, 2005 2:44 am

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: Select all
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: Select all
   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: Select all
      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 ??
User avatar
relicviper
New php-forum User
New php-forum User
 
Posts: 21
Joined: Tue Apr 22, 2003 10:02 pm
Location: South Africa, JHB

Postby relicviper » Thu Mar 31, 2005 11:23 pm

just for interest sake

eval()

was what helped me out.
User avatar
relicviper
New php-forum User
New php-forum User
 
Posts: 21
Joined: Tue Apr 22, 2003 10:02 pm
Location: South Africa, JHB


Return to JavaScript

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.