Home › Forums › Quform WordPress › Add sum of combobox values to inputbox …
- This topic has 6 replies, 4 voices, and was last updated 11 years, 4 months ago by Ally.
- AuthorPosts
- June 26, 2013 at 5:19 pm #5050TekanewaParticipant
I have several combo-boxes with conditional logic applied to them in my form and I would like to add the total of the individual combo-box values into another text-box at the bottom of the form. I also need the text-box that shows the total amount to be blocked from editing by the form user so that the calculated sum can not be changed.
How can I do that?
Thank you!
June 27, 2013 at 3:27 pm #5057AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 27, 2013 at 4:45 pm #5060TekanewaParticipantAfter some tinkering, the following code seems to do what I need, although there might be a better way to program it:
There are 5 select boxes($day1 – $day5) with conditional logic applied ($logic) and the script is supposed to add only those select boxes that are visible. Also, the input box that is showing the total number will be set to read-only so the user can’t overwrite the calculated value:
<script type="text/javascript">
jQuery(function($) {
$('.iphorm_4_90').attr('readonly', true);
var $logic = $('.iphorm_4_54');
var $day1= $('.iphorm_4_49');
var $day2= $('.iphorm_4_50');
var $day3= $('.iphorm_4_75');
var $day4= $('.iphorm_4_76');
var $day5= $('.iphorm_4_77');
$logic.change( function(){Add_All_Hours();});
$day1.change( function(){Add_All_Hours();});
$day2.change( function(){ Add_All_Hours();});
$day3.change( function(){Add_All_Hours();});
$day4.change( function(){Add_All_Hours();});
$day5.change( function(){Add_All_Hours();});
function Add_All_Hours() {
var $days = $('.iphorm_4_54').val();
var totalHours = 0;
if ($.isNumeric($day1.val()) && parseFloat($days) > 0) {
totalHours = totalHours + parseFloat($day1.val());
}
if ($.isNumeric($day2.val()) && parseFloat($days) > 1) {
totalHours = totalHours + parseFloat($day2.val());
}
if ($.isNumeric($day3.val()) && parseFloat($days) > 2) {
totalHours = totalHours + parseFloat($day3.val());
}
if ($.isNumeric($day4.val()) && parseFloat($days) > 3) {
totalHours = totalHours + parseFloat($day4.val());
}
if ($.isNumeric($day5.val()) && parseFloat($days) > 4) {
totalHours = totalHours + parseFloat($day5.val());
}
$('.iphorm_4_90').text(totalHours);
$('.iphorm_4_90').val(totalHours);
}
Add_All_Hours();
});
</script>
June 27, 2013 at 4:49 pm #5063AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 2, 2013 at 3:46 am #5078LifeischoiceParticipantHello Takanewa,
Thanks for sharing the code….Please where did you put the code above?
July 2, 2013 at 6:52 pm #5089tmh2k1ParticipantHi Ally,
Is there any way to add the sum of single line fields? I just need the user to see the total number of beer cases that hey are ordering.
Attached is a screen shot of the lines I need a total for. Thank you.
Attachments:
You must be logged in to view attached files.July 5, 2013 at 12:18 pm #5126AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.