Skip to main content
Known Participant
September 15, 2016
Question

Conditional Addition

  • September 15, 2016
  • 3 replies
  • 436 views

Good Afternoon,

I am working on a form for a raffle.  Tickets range in prices 1 ticket is $1.00, 10 tickets is $5.00, and 25 tickets for $10.00.  What I would like to figure out is, if someone types in the number of tickets they want under the ticket column the total of tickets and prices with add up and be displayed in the $$ amount/Total # tickets area.  Let's say they want 10 tickets and then buy 1 more single ticket.  The total for them would be $6.00.  Or let's say they would like 25 tickets and then another 10 tickets, the total would come to $15.00.  I hope I am making sense with what I am trying to figure out here.   Here is a screen shot of what the form looks like.

This topic has been closed for replies.

3 replies

Inspiring
September 15, 2016

You can do this with a custom calculation JavaScript. Without knowing the field names if the "# Tickets" fields, it's hard to suggest a specific script that you can use. What are the "Basket #" fields for?

justiggerAuthor
Known Participant
September 16, 2016

I redesigned the form.  The field names are present now.  The basket number boxes and nothing, those will be entered in manually.  What I am trying to accomplish is, when the total number of tickets is calculated, it reflects the ticket prices.  example:  if someone wanted one ticket, it would total $1.00.  10 tickets for $5.00 and 25 tickets for $10.00.  But, if the person were to order 12 tickets, it would total $7.00 ($5.00 for the 10 and $2 for the 2 single tickets).  Is this something that is doable?

try67
Community Expert
Community Expert
September 16, 2016

You can do it using this code as the custom calculation script of the Amount Due field:

var tickets = Number(this.getField("Total Number of Tickets").value);

var totalPrice = 0;

while (tickets>=25) {

    tickets-=25;

    totalPrice+=10;

}

while (tickets>=10) {

    tickets-=10;

    totalPrice+=5;

}

while (tickets>0) {

    tickets-=1;

    totalPrice+=1;

}

event.value = totalPrice;

justiggerAuthor
Known Participant
September 15, 2016

Sorry about that.  I am using Adobe Acrobat

John T Smith
Community Expert
Community Expert
September 15, 2016

The Forum Lounge is not for technical help, please provide the name of the program you are using so your message may be moved to the correct program forum