Hi Guys
The following question is related to the following url:
http://www.sheltonwebdevelopment.com/blog/2010/03/01/calculating-totals-with-jquery/

I have just a small question now regarding the dropdown. I am sure its related to an 'id'.
Here is my script:

1.
      <td><?php echo "<select name=\"field1\" class=\"qty\" onchange=\"calcTotal();\">"; ?>
   2.
      <?php
   3.
      for($i=0;$i<=50;$i++){
   4.
      echo '<option value="'.($i+$credit).'">'.$i.'</option>';
   5.
      }
   6.
      ?>
   7.
      </select>
   8.
      </td>

<td><?php echo "<select name=\"field1\" class=\"qty\" onchange=\"calcTotal();\">"; ?> <?php for($i=0;$i<=50;$i++){ echo '<option value="'.($i+$credit).'">'.$i.'</option>'; } ?> </select> </td>

Currently its adding all fields in my dropdown value to the first box.
I currently have 2 table rows for testing.

How can I tell this script to add each rows values separately?

Hope someone can help me.

You need to pass to calcTotal a reference to the select menu that has been changed:

<select name="field1" class="qty" onchange="calcTotal(this);">

Then, calcTotal will be something like:

function calcTotal(menu){
  var total = 0;
  for(var i=0; i<menu.length; i++) {
    total += Number(menu[i].value);
  }
  alert(total);//or whatever you want to do with the result
}

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.