can't get form designer to calculate...

User 2885601 Photo


Registered User
25 posts

I'm creating an online raffle ticket purchase form for a non-profit home for the disabled using coffeecup form designer. Raffle tickets are $5.00 each. I have a "select" element which allows from 1 to 20 tickets to be selected for purchase. I have a text field named "OrderTotal" that I want to have auto sum the cost of the number of tickets. I've adapted a script which was developed by Eric Rohloff on another project I worked on in Web Form Builder and inserted it as an HTML element.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script>var jQ = $.noConflict(true);
// version 1
var Number_Tickets = 5;

jQ( document ).ready(function() {
// Set TotalOrder to read only
jQ('input[name="OrderTotal"]').prop('readonly', true);

jQ('select[name="Number_Tickets"]').on('change', function() {
if (jQ(this).val()!=0){
jQ('select[name="Number_Tickets"]').data('price',Number_Tickets);

}else{jQ('select[name="Number_Tickets"]').data('price','');};
calc_dues();
});

// This is the calculate function
function calc_dues() {
jQ('input[name="OrderTotal"]').val(sum_price);
var sum_price = 0;

jQ('select[name^="C"]').each(function(){

if(this.value!= 0 && jQ(this).data('price')!=''){

sum_price += parseFloat(this.value) * parseFloat(jQ(this).data('price'));
jQ('input[name="OrderTotal"]').val("$"+sum_price.toFixed(2));
}
});

}
});</script>


In the Dropdown Element properties in Web Form Builder offers a "Payment" option where I can select price multiplier and set the price. The Select Element in Form Designer has no such selection. I'm wondering if this is accomplished with setting the right attributes.

I don't know how to proceed and would appreciate some assistance. I tried to attach the Form Designer File but I get this error message:
Sorry, we couldn't start the thread for the following reasons:Your attachment must be one of: .TXT, .SNP, .ZIP, .RSD, .RLM, .RLMP, .RED, .GIF, .JPG, or .PNG format.

So instead I'm inserting a dropbox link: https://www.dropbox.com/s/c05rn441nvc5gs9/QueenOfHearts.fdp?dl=0
User 187934 Photo


Senior Advisor
18,798 posts

Hi james,
Give this a try.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
// version 1
var jQ = $.noConflict(true);
var Ticket_Price = 5;
var Total = 5;
jQ( document ).ready(function() {
// Set OrderTotal to read only
jQ('input[name="OrderTotal"]').prop('readonly', true);
jQ('input[name="OrderTotal"]').val(Total);
jQ('select[name="Number_Tickets"]').on('change', function() {
if (jQ(this).val()!=5){
Total = jQ('select[name="Number_Tickets"]').val()* Ticket_Price ;
jQ('input[name="OrderTotal"]').val(Total);
}else{jQ('input[name="OrderTotal"]').val(Total);};
});
});</script>
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

Here's my S-Drive site with
examples of what can be accomplished in VSD.
https://progrower.coffeecup.com/
Here's my CoffeeCup SCCP Shop with examples of what can be done.
https://progrower.coffeecup.com/shop/
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 2885601 Photo


Registered User
25 posts

Eric,
Many thanks - this works perfectly. Can I make one additional request? Can you add the language that causes the result to appear in a "currency" format such as $5.00?

Again thanks so much for all of your help.

Jim Capraro
User 187934 Photo


Senior Advisor
18,798 posts

Try this.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
// version 2
var jQ = $.noConflict(true);
var Ticket_Price = 5;
var Total = 5;
jQ( document ).ready(function() {
// Set TotalOrder to read only
jQ('input[name="OrderTotal"]').prop('readonly', true);
jQ('input[name="OrderTotal"]').val("$"+Total+".00");
jQ('select[name="NumberTickets"]').on('change', function() {
if (jQ(this).val()!=5){
Total = jQ('select[name="NumberTickets"]').val()* Ticket_Price ;
jQ('input[name="OrderTotal"]').val("$"+Total+".00");
}else{jQ('input[name="OrderTotal"]').val("$"+Total+".00");};
});
});</script>
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

Here's my S-Drive site with
examples of what can be accomplished in VSD.
https://progrower.coffeecup.com/
Here's my CoffeeCup SCCP Shop with examples of what can be done.
https://progrower.coffeecup.com/shop/
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 2885601 Photo


Registered User
25 posts

Perfect - thank you so very much, Eric. I'll post a link back here to the form when it's sone.

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.