0

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.

Edited by schalkl: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Airshow
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.