sum text field depend on the other drop down's value

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Lphp
Forum Commoner
Posts: 74
Joined: Sun Jun 26, 2011 9:56 pm

sum text field depend on the other drop down's value

Post by Lphp »

for(int i=0; i<=6, i++){
<tr>
<td><span class="amtxt" >
<input type="text" name=amacount></span>
</td>
<td class="w6"><select id="level" class="sum" name="level" size="1">
<option value="">-- Please select --</option>
<option value="K1">K1</option>
<option value="K2">K2</option>
<option value="K3">K3</option>

</select></td>
</tr>
}
I want six rows, I want to get the sum for all sumK1, sumK2 ,sumK3
so far I have, but did not get what I want

Code: Select all

$(".sum").each(function() {

				if ($(this).children().val() == "K1") {
					alert(am_value + $(this).children().val());
				
					sumk1+=(!isNaN(am_value) && $.isNumeric(am_value)) ? parseInt(am_value) : 0;
				
				}	

			});
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: sum text field depend on the other drop down's value

Post by requinix »

"K1" isn't a number. You can't sum those...

Code: Select all

$(this).children().val()
That will get the value of the first child. You need just $(this).val() for the value of the select.

And if you haven't already, sumk1 has to be defined before and outside the each().
Lphp
Forum Commoner
Posts: 74
Joined: Sun Jun 26, 2011 9:56 pm

Re: sum text field depend on the other drop down's value

Post by Lphp »

i have two column i did not sum K1 , I sum every number relate to K1 and I have the sum define outside each
Post Reply