Skip to main content
hayleyl39888723
Participant
November 13, 2017
Answered

Java Script for Check box to update text

  • November 13, 2017
  • 1 reply
  • 686 views

Hello,

I have 1 checkbox with the name taxable and 2 fields with the name CashPrice and TaxableTotal. And in text1 there is a value.

Now comes my question if i check the checkbox the value of CashPrice needs to be added to the TaxableTotal. There are 8 lines that will needed to be able to be added. I don't know how to begin.

Can someone help me with this script ?

This topic has been closed for replies.
Correct answer try67

OK, that's better. You can use this code as the custom calculation script of your total field:

var total = 0;

for (var i=1; i<=8; i++) {

    if (this.getField("Taxable"+i).value!="Off")

        total+=Number(this.getField("CashPrice"+i).value);

}

event.value = total;

1 reply

try67
Community Expert
Community Expert
November 13, 2017

It's possible, but you need to better explain the situation... Where does "text1" fit into this? What are the names of the 8 fields? Is it 8 pairs of check-boxes and text fields, or something else? Please clarify.

hayleyl39888723
Participant
November 13, 2017

I apologize in CashPrice there is a value... text1 doesn't fit in this one that was an accident. It is 8 pairs of check boxes and fields. The check boxes are named Taxable1, Taxable2, Taxable3....Taxable8 the text fields are CashPrice1, CashPrice2....CashPrice8.

This is a form used for a purchase order. My goal is to find the total of the equipment that is taxable, so that I can figure the tax in a later box.

By trial and error and lots of reading I have figured out several of the other scripts that I have used, but this one has stumped me.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 13, 2017

OK, that's better. You can use this code as the custom calculation script of your total field:

var total = 0;

for (var i=1; i<=8; i++) {

    if (this.getField("Taxable"+i).value!="Off")

        total+=Number(this.getField("CashPrice"+i).value);

}

event.value = total;