Page 1 of 1

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

Posted: Mon Sep 05, 2016 9:49 am
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;
				
				}	

			});

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

Posted: Mon Sep 05, 2016 8:13 pm
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().

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

Posted: Mon Sep 05, 2016 8:41 pm
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