Graeme McGilvray
asked on
Autosum input type=text when checkbox is true
Hi all and thanks in advance for your help
I am looking to create an account page to match up sums
So I would like the checked amounts to autosum into either debittotal or credittotal (which ever side they are)
Then it will sum to totalrecon
Cheers
I am looking to create an account page to match up sums
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=672>22/04/2016</a></td>
<td>SureSave Account</td><td>Comm return</td><td align=right><input type='text' size=10 name='debitamount' value=-$63.00></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=618>28/04/2016</a></td>
<td>Air Tickets Account</td><td></td><td align=right><input type='text' size=10 name='debitamount' value=$1,471.24></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=701>29/04/2016</a></td>
<td>SureSave Account</td><td>Comm return</td><td align=right><input type='text' size=10 name='debitamount' value=-$45.60></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=621>2/05/2016</a></td>
<td>Air Tickets Account</td><td></td><td align=right><input type='text' size=10 name='debitamount' value=$262.54></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=622>2/05/2016</a></td>
<td>Air Tickets Account</td><td></td><td align=right><input type='text' size=10 name='debitamount' value=$262.54></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=662>5/05/2016</a></td>
<td>Commission Transfer</td><td> </td><td align=right><input type='text' size=10 name='debitamount' value=$33.31></td><td> </td>
</tr>
<tr>
<td colspan=4>TOTALS</td>
<td align=right><input type="text" name="debittotal" size=10></td>
<td align=right><input type="text" name="credittotal" size=10></td>
</tr>
<tr>
<td colspan=4>Recon Amount</td>
<td align=right><input type="text" name="amounttorecon" size=10></td>
<td align=right><input type="text" name="totalrecon" size=10 placeholder="Total Recon Amount" disabled</td>
</tr>
So I would like the checked amounts to autosum into either debittotal or credittotal (which ever side they are)
Then it will sum to totalrecon
Cheers
ASKER
Hi Big Monty, what I have so far is just the layout for what I want, nothing else (code above)
Add a class name to each of your individual text box that you want to add. Call it "addUp". Then, you could use the following jquery to add up each of those text boxes:
I don't really understand what " to autosum into either debittotal or credittotal (which ever side they are)" means, so let's skip that part for now. Put in the code above, see if you can get that working, then report back.
$(document).on("change", ".addUp", function() {
var sum = 0;
$(".addUp").each(function(){
sum += +$(this).val();
});
$("#totalrecon").val(sum);
});
I don't really understand what " to autosum into either debittotal or credittotal (which ever side they are)" means, so let's skip that part for now. Put in the code above, see if you can get that working, then report back.
ASKER
Hi, sorry was away for a tournament
thanks for the help BigMonty as always, I have applied the code you have suggested:
looking at the page itself, i cant see any physical difference... is this correct?
thanks for the help BigMonty as always, I have applied the code you have suggested:
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=672>22/04/2016</a></td>
<td>SureSave Account</td><td>Comm return</td><td align=right><input type='text' size=10 name='debitamount' value=-$63.00 class="addUp"></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=618>28/04/2016</a></td>
<td>Air Tickets Account</td><td></td><td align=right><input type='text' size=10 name='debitamount' value=$1,471.24 class="addUp"></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=701>29/04/2016</a></td>
<td>SureSave Account</td><td>Comm return</td><td align=right><input type='text' size=10 name='debitamount' value=-$45.60></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=621>2/05/2016</a></td>
<td>Air Tickets Account</td><td></td><td align=right><input type='text' size=10 name='debitamount' value=$262.54 class="addUp"></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=622>2/05/2016</a></td>
<td>Air Tickets Account</td><td></td><td align=right><input type='text' size=10 name='debitamount' value=$262.54 class="addUp"></td><td> </td>
</tr>
<tr>
<td align=center><input type="checkbox" name="transID"></td>
<td><a href=?account=2&transaction=662>5/05/2016</a></td>
<td>Commission Transfer</td><td> </td><td align=right><input type='text' size=10 name='debitamount' value=$33.3 class="addUp"1></td><td> </td>
</tr>
<tr>
<td colspan=4>TOTALS</td>
<td align=right><input type="text" name="debittotal" size=10></td>
<td align=right><input type="text" name="credittotal" size=10></td>
</tr>
<tr>
<td colspan=4>Recon Amount</td>
<td align=right><input type="text" name="amounttorecon" size=10></td>
<td align=right><input type="text" name="totalrecon" size=10 placeholder="Total Recon Amount" disabled</td>
</tr>
<script type="text/javascript">
$(document).on("change", ".addUp", function() {
var sum = 0;
$(".addUp").each(function(){
sum += +$(this).val();
});
$("#totalrecon").val(sum);
});
</script>
looking at the page itself, i cant see any physical difference... is this correct?
please set up a jsFiddle and we can diagnose it from there
ASKER
sorry, jsFiddle?
jsFiddle is a site where you can write out html / javascript all on the same page and allow others to view and run it. Essentially it'll allow for us to collaborate together on the code
ASKER
ASKER
Hi BigMonty, how did you go with my Fiddle? :)
ASKER
I'll try to get to this within the next few days, as I'm on travel in Australia right now
ASKER
Oh are you? Im in Aus! :) Where abouts are you?
And no issues with getting to it :)
And no issues with getting to it :)
I visiting Melbourne for 2 weeks... How about you?
ASKER
I'm on the other side of Aus in Perth. Welcome! Too bad the weather isn't flash!
Hehe thanks... Weather here is a lot nicer than Boston, where it's hotter than hell :)
ASKER
I was in Boston in OCT/NOV last year, definitely do not remember it being hot :P
ASKER
This is still ongoing, please keep open
i just got back from australia today, will have a look later on to resume this question
ASKER
fantastic, thank you
have a go with this fiddle and let me know if I'm close. If so, I'll do a write up explaining more what you need to do to incorporate it into your code if you like:
https://jsfiddle.net/bigmonty/kkna3mxq/2/
https://jsfiddle.net/bigmonty/kkna3mxq/2/
ASKER
Thanks for the BigMonty, working great, however for some reason when line 2 is checked with the line above or below, it doubles the value? very strange
ASKER
Hey mate, how did you go on this?
I'll try to have a look at both of your questions later on today. I think we're really close and should have a solution for you soon.
ASKER
fantastic! thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works perfect! Thank you!
can you show us what you've gotten so far and where you need help?