3 Replies Latest reply on Jun 22, 2009 2:02 PM by gkaiseril

    Help with Javascript/Calculations




      Have a building use policy for school.


      Need help with checkboxes and default values.  I can get javascript/math to work when I click check box.

      Someone wants to rent a room they check the rentRoom checkbox.  Then the enter how many rooms 1,2,3 etc..  The value for the rentRoom checkbox is $25.


      I can get it when the checkbox for rentRoom is selected the rentRoom.Total computes correctly.  However, what I want is when the form opens up a default value of $0.00 to be in there.  I also want if someone goes back and unchecks the rentRoom checkbox the value goes back to $0.00 not just blank.   Right now I am getting the error the value entered does not match the value of the field.  That is if I put the default value in options.  Basically, I can't seem to figure out the javascript code to get this to work.


      Am I asking for too much, can someone guide me to javascript to help me out.


      I have tried if/then statements and switch statements.  I just can't figure out how to get it to for lack of better a word - toggle back and forth.


      If this is not possible please tell me.  If it is too complicated tell me.  I am not using livecycle for this as we had a word document and I just used the find form fields.  I am also using Adobe Acrobat 8 Professional.



        • 1. Re: Help with Javascript/Calculations
          gkaiseril MVP & Adobe Community Professional

          In ArcoForms, a form designed in Acrobat, the value of an unchecked check box or radio button is the text string "Off". So you need to adjust your calculation to test for the value of 'Off' or check to see if the value is not 'Off'.


          // get value of the check box

          var RoomPrice = this.getField('CheckBoxFieldName').value;

          // see if RoomPrice is equal to 'Off'

          if(RoomPrice == 'Off") {

          RoomPrice = 0; // change 'Off' to zero


          event.value = RoomPrice * this.getField('NumberRoomsField').value;

          • 2. Re: Help with Javascript/Calculations
            cschoon Level 1



            Thanks that looks good.  I am still missing something but the calc doesn't work when I put in my variables.  I will work with it more but nothing happens.


            The one thing is I have the default value of the checkbox as 15 so don't know if that messes it up.


            Right now I get the default value of $0.00 all the time.  When I click on the check box on/off it doesn't do the calcs.


            sorry, any more input, what am i missing??


            I also changed the syntax error that was posted on your origianl post.  You had == 'Off" I changed that to 'Off'

            • 3. Re: Help with Javascript/Calculations
              gkaiseril MVP & Adobe Community Professional

              The script is for a 'Custom calculation script' for the field with the amount for the room.


              That is correct the string needs to be terminiated.


              Setting the export value to '15' will cause the a problem. You can just change using the value of the field to the number '25' or change the export value to '25'.