8 Replies Latest reply on Sep 16, 2013 1:28 PM by petermarksATL

    Custom calculation script for a lease (please help)

    petermarksATL

      I have so little experience with this it isn't funny.  I prior to now have never used javascript.  But Im trying to get my lease form to auto calculate a tenants pro-rate that would be due if they moved in on the middle of the month for example.

       

      I created the below script and im sure there is a few things or more than a few things wrong with it...can anyone give me some pointers.

       

       

      // Custom Calculate script

      (function () {

         

          // Get the input field values, as strings

          var leasemonth = getField("LeaseBegMonth").valueAsString;

          var leasestartday = getField("LeaseBegDay").valueAsString;   
          var rentamount = getField("MonthlyRent").valueAsString;

         

          // calculate how many days in the month

          if ( leasemonth=1
                  var leasedays = 31
              )
          elseif (leasemonth=2
                  var leasedays = 28
              )
          elseif (leasemonth=3
                  var leasedays = 31
              )
          elseif (leasemonth=4
                  var leasedays = 30
              )
          elseif (leasemonth=5
                  var leasedays = 31
              )
          elseif (leasemonth=6
                  var leasedays = 30
              )
          elseif (leasemonth=6
                  var leasedays = 30
              )
          elseif (leasemonth=7
                  var leasedays = 31
              )
          elseif (leasemonth=8
                  var leasedays = 31
              )
          elseif (leasemonth=9
                  var leasedays = 30
              )
          elseif (leasemonth=10
                  var leasedays = 31
              )
          elseif (leasemonth=11
                  var leasedays = 30
              )
          elseif (leasemonth=12
                  var leasedays = 31
              )           

       

          //CALCULATE HOW MANY DAYS REMAIN
          var daysremain = LeaseBegDay-leasedays   


          //CALCULATE THE PRORATE AND DISPLAY IT
          event.value = (rentamount/leasedays)* daysremain
         

      })();

       

      Thanks for your help!!