2 Replies Latest reply on Jul 18, 2012 10:50 AM by nabnub

    Custom Calculation Script for percentages


      Hi everyone,




      can someone help me, I am trying to write a script, but I face some unsatisfactory results


      I upload the form so you can have a look at it:




      he re is the scenario:


      so after selecting the different module code

      the fields: Excellent, Good, Satisfactory and Unsatisfactory have different values (they have a script)


      eg. if Y1H3 is selected, excellent will be at 33.33 % etc...


      but then I would like that when the Grade is selcted (Grade 1, Grade 2 ....) the fields ( MarksRow1, MarksRow2 ...) take the correspondant value of the fields: Excellent, Good, Satisfactory and Unsatisfactory



      I've tried to write for each of the field MarksRow1, MarksRow1 etc...  the following script this but it doesn't work



      (function () {
          var z = getField("Grade 1").value;
      if (z === 0) {
              event.value = "";
       if (z === 3) {
              event.value = getField("Excellent").value;
      if (z === 4) {
              event.value = getField("Good").value;
      if (z === 5) {
              event.value = getField("Satisfactory").value;
      if (z === 6) {
              event.value = getField("Unsatisfactory").value;


      I would like after that to work out the total in the MarksTotal field by adding the value of ( MarksRow1, MarksRow2 ...)




      can you help me please?



        • 1. Re: Custom Calculation Script for percentages
          George_Johnson MVP & Adobe Community Professional

          The dropdown (combo box) "Grade 1" has items with exports values of 0, 1, 2, 3, and 4. The script you posted that is the calculation script for the "MarksRow1" fields checks for the values 0, 3, 4, 5, 6. Since 5 for 6 is not possible, and it doesn't handle the cases where it's equal to 1 or 2, you have to fix it.


          Regarding the MarksTotal field, exactly what to you want to sum? The values of the MarksRow fields are strings, not numbers. Do you mean that you want to sum the values of the "Grade1" - "Grade 11" fields?

          • 2. Re: Custom Calculation Script for percentages
            nabnub Level 1

            hi George,


            thank you for your interest



            I've just realised that I was complety wrong in the differents tests,  there is no 5 and 6 but only 0,1,2,3 and 4


            and now it's working, thanks


            yes for the total, basically after selecting the different grade, it will display a percentage on the marks column fields ( "MarksRow1"- "MarksRow11" )


            I would like to add this percentages and display the total in the MarksTotale field

            also I would like to leave this field (MarksTotal) empty if nothing has been selected


            I've tried to to do this, but there is a zero when nothing has been selected and it doesn't display the % sign next the total


            here is the form: http://cjoint.com/?BGstXulF9PX