Keeping a running cost total - Page 1...

User 2208850 Photo


Registered User
40 posts

A question for Eric ...

I'm trying to use your script from here - http://ericrohloff.com/coffeecup/ccforum/formbuilder/coffeecup-forms/total_cost_grand/ but just cannot seem to get it to work. I've obviously got something totally wrong but cannot figure out what - http://www.idhsgb.com/iForms-test/conformtest/conformtest.php

Any help greatly appreciated.
'A computer lets you make more mistakes faster than any other invention with the possible exceptions of handguns and Tequila.'
User 2208850 Photo


Registered User
40 posts

Think I need to look at this again when \I get home - I think I've used text boxes instead of numbers
:D:lol:
'A computer lets you make more mistakes faster than any other invention with the possible exceptions of handguns and Tequila.'
User 2208850 Photo


Registered User
40 posts

Still can't get it to work .... I've even made a new form identical to Eric's example and that don't work either !!!!
It's probably something totally obvious, but I just aint seeing it :(

Help !!!

http://www.idhsgb.com/iForms-test/conformtest/conformtest.php

http://www.idhsgb.com/iForms-test/total/total.php
'A computer lets you make more mistakes faster than any other invention with the possible exceptions of handguns and Tequila.'
User 187934 Photo


Senior Advisor
20,271 posts

At the end of the script hit enter on this line after total.
// your grand total }

so it looks like this.
// your grand total
}
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2208850 Photo


Registered User
40 posts

This has got it working on the first of the two boxes (item2_text_1 on http://www.idhsgb.com/iForms-test/total/total.php), 2nd item totals but does not add to grand total.

Also, I assume to change display of $ to £, I would change all the $ in the script ?
'A computer lets you make more mistakes faster than any other invention with the possible exceptions of handguns and Tequila.'
User 187934 Photo


Senior Advisor
20,271 posts

No only these.
"$"

Also I redid the form to use $('input[name="item1amount"]') jquery target to make it easier to do. Now you just make your input names match mine in my code.

text1 === Subtotal cost for item 1
text2 === Subtotal cost for item 2
item1amount === Number of item 1
item2amount === Number of item 2
grandtotal === Your grand total input



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">$(document).ready(function(){
//The inputs you want read only and the sumtotal class set to
$('input[name="text1"]').attr('readonly', true);// name of item 1 subtotal $
$('input[name="text1"]').addClass('sumtotal');
$('input[name="text2"]').attr('readonly', true);// name of item 2 subtotal $
$('input[name="text2"]').addClass('sumtotal');
$('input[name="grandtotal"]').attr('readonly', true);// name of grand total $

// name of amount of item 1
$('input[name="item1amount"]').bind('keyup keypress click blur',function(){
var valone = $('input[name="item1amount"]').val();
var valtwo = 13.00;
var total1 = ((valone * valtwo));
if(valone > 0){
$('input[name="text1"]').val(total1.toFixed(2)); // cost sub total of item 1
calculateSum();
}else if (valone == ""){
$('input[name="text1"]').val("");
}
if ($('input[name="item1amount"]').val()== "" && $('input[name="item2amount"]').val()==""){
$('input[name="grandtotal"]').val("");
}
});
// name of amount of item 2
$('input[name="item2amount"]').bind('keyup keypress click blur',function(){
var valone = $('input[name="item2amount"]').val();
var valtwo = 22.00;
var total2 = ((valone * valtwo));
if(valone > 0){
$('input[name="text2"]').val(total2.toFixed(2)); // cost sub total of item 2
calculateSum();
}else if (valone == "" ){
$('input[name="text2"]').val("");
}
if ($('input[name="item1amount"]').val()== "" || $('input[name="item2amount"]').val()==""){
calculateSum();
}
});
function calculateSum() {
var sum = 0;
$('.sumtotal').each(function() {
var text = $(this).val().replace("$", "");
$(this).val(text);
//console.log($(this).val());

if(this.value!="" && this.value.length!=0) {
sum += parseFloat(this.value);
$(this).val("$" + $(this).val());

}

});
$('input[name="grandtotal"]').val("$"+sum.toFixed(2)); // grand total
}

});

</script>


You can see it here.
http://ericrohloff.com/coffeecup/ccforu … d_new.html
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2208850 Photo


Registered User
40 posts

Brilliant Eric, now working perfectly ....... I'll have to keep working on the other way, see if I can figure out where I was going wrong.

One more question .... as the 'grand total' is a text box is there a way I can get this to go to Paypal when 'submit' is pressed?
'A computer lets you make more mistakes faster than any other invention with the possible exceptions of handguns and Tequila.'
User 187934 Photo


Senior Advisor
20,271 posts

Yes, Add another input that's paypal enabled and keep it hidden with css and use JQuery to fill it in with just the total amount without the dollar sign.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2208850 Photo


Registered User
40 posts

Yes, Add another input that's paypal enabled and keep it hidden with css and use JQuery to fill it in with just the total amount without the dollar sign.


I thought of adding a paypal enabled box that the user completes (not very elegant but workable), but how would I do it as you suggest?
'A computer lets you make more mistakes faster than any other invention with the possible exceptions of handguns and Tequila.'
User 187934 Photo


Senior Advisor
20,271 posts

Add another number input named actual_grandtotal
Now use the code I adjusted on my form.
http://ericrohloff.com/coffeecup/ccforu … ost_grand/
New is this to hide the input and label. Mine was #item9
<style>#docContainer #item9{display:none;}
</style>

Then this line to fill the actual grandtotal
$('input[name="actual_grandtotal"]').val(sum.toFixed(2)); // actual grand total

If you click on the email input on my form you can see the hidden input.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.