JavaScript to divide unevenly

Hey guys,.

So I worked on a form in Adobe Acrobat Pro XI and I came up with some things I have to do with Javascript - but I can't work quite how. Any help would be greatly appreciated!

The problem slightly curly, is that I have a box that has a total of principal, and I then divide this total by three new boxes. Simple enough except that in the case of a number which is not evenly divide by 3, I don't want fractions. I want to divide unevenly and so that he can put the largest number in, say, box 3, then 2 if there is still another.

I'll give you an example: If the Total is 28, I would other boxes to be: 1.8 electric box 2:8 box 3:9

If the total area is 29, I would that the three cases derived to be: box 1:8, 2:9 box, box 3:9

Hope that makes sense!

The formula I use now is: event.value = (this.getField("Total_Health").value / 3)

This divides the area into three and gives a fraction (so that the case of 28, it gives 9.33333333...)

See you soon!

Then replace Math.floor with Math.round in the code above.

Tags: Acrobat

Similar Questions

  • This just error message started appearing yesterday: Application JavaScript - TypeError: window CloseAlert not a function.

    Application of JavaScript - TypeError: window of the CloseAlert not a function.

    What causes this error, can you help me fix?

    I use Windows 7 and the latest browser Foxfire.

    • If you have many extensions then first turn on half of test extensions that half the problem.
    • Continue to divide the bad half that still has the question until you find that one is causing it.
  • JavaScript to display the field date in the format below

    I'm a customer form who need the date to display in the format below

    As if he puts day 13/05/2015 then it should show that may 13, 2016 (Please note that there should be "th" after 13)

    19/07/2016 should show that July 19, 2016 (an' th' after only 19 should be here)

    Thanking you

    This way of listing of numbers is known as "Ordinal". There are many was to this script. What works for the web that JavaScript can easily work with few changes in Acrobat Forms. This type of date format is generally used in legal forms.

    You should be able to search the forums for "legal date" or "ordinal" and find the post.

    I found a JavaScript function that can take a number of entry and returns the number with the ordinal suffix. This allows you to create any number of date formats.

    This function is not limited to a few dates bat can be used to add the ordinal suffix to a number any.

    The function:

    function ordinal_suffix_of (I) I have

    {

    var j = i % 10, / / tens of rest

    k = i % 100, //100's remains

    cSuffix = "e"; results of default suffix

    If (j == 1 & k! = 11) {}

    No 11;

    cSuffix = "m";

    }

    If (j == 2 & k! = 12) {}

    No 12;

    cSuffix = "nd";

    }

    If (j == 3 & k! = 13) {}

    No 13;

    cSuffix = "rd";

    }

    return i + cSuffix;

    } / / end of function ordial_suffix;

    I put this code in the location of the script to document level and then call it as necessary in the various areas.

    I enter the date in a different area that would not print and then have the date formatting in another area. You know how to divide the date entered in the month, string date and year, parts and then rearrange them as needed.

    You can test the code using the Acrobat JavaScript console:

    function ordinal_suffix_of (i)
    {
    var j = i % 10, / / tens of rest
    k = i % 100, //100's remains
    cSuffix = "e"; results of default suffix
    If (j == 1 & k! = 11) {}
    No 11;
    cSuffix = "m";
    }
    If (j == 2 & k! = 12) {}
    No 12;
    cSuffix = "nd";
    }
    If (j == 3 & k! = 13) {}
    No 13;
    cSuffix = "rd";
    }
    return i + cSuffix;
    } / / end of function ordial_suffix;

    function MyDateFormat (cFormat, cDate)
    {
    Kai var = util.scand (cFormat, cDate);
    if(oDate == null)
    {app.alert ("invalid date provided", 1, 0);}
    }
    on the other
    {
    "Return util.printd ("mmmm", letter) +" "+ ordinal_suffix_of (oDate.getDate ()) + ', ' + util.printd ("yyyy", anyway);"
    }
    }

    var dateInput = "13/05/2015; value of date entered;
    var cFormattedDate = MyDateFormat ("d/mm/yyyy", dateInput); formatted string for the date;
    Console.println (cFormattedDate);
    dateInput = ' 23/05/2015;
    Console.println (MyDateFormat ("d/mm/yyyy", dateInput));
    dateInput = "19/07/2015;
    Console.println (MyDateFormat ("d/mm/yyyy", dateInput));
    dateInput = "09/07/2015;
    Console.println (MyDateFormat ("d/mm/yyyy", dateInput));

  • Passing values to Javascript arrays

    I am trying to wrap my head around its replacement and combining tables in Javascript. I found a code that strives to combine paintings, deduplicate and then sort by alphabetical order (see below).  My question is, how can I fill these tables with the other values which are chosen by the user, rather than define it myself in JS?  For example, if a user clicks a different button, I would that array1 must be closed with 4 new animal names?  I think there is a way to assign a CSV string to the value of the variable Captivate and it divided into values in table in JS. Thank you.

    Array.prototype.unique = function() {}

    var a = this.concat ();

    for (var i = 0; I <.) Length; (++ I) {}

    for (var j = i + 1; j <.) Length; ++ j) {}

    If (a [i] = a [j])

    a.splice (d, 1);

    }

    }

    return a;

    };

    Array1 var = ["cat", "dog", "snake", "shark"];

    Array2 var = ["frog", "cow", "eagle", "shark"];

    var arrayFinal = array1.concat (array2) Futuroscope ();

    Alert (arrayFinal.sort ());

    If you put the JavaScript code in the head of your index.htm just after the

  • The window run JavaScript does not allow "&lt;" to a string value.

    Does not allow to execute javascript window ' < ' in certain uses. For example it would not accept "if (x < y) {}", but it would allow "if (y > x)...". »

    In this case, I was able to work around it.

    An example, I can't work around attaches a string containing value ' < ':

    customCSS = "< style type =" text/css"> #myStyle {left: 1014px!}" important; top: 47px ;} < / style > ";

    It always divides the string after the "before the <."

    Does anyone know a way to escape to the < character? I know that I can do as an external function, but I am trying to create a current template with all the internal scripts.

    Thank you.

    I use an external CSS file that is published with the file.

    You can use JavaScript to write the new rule in a style sheet, or create a new. In this way, you don't have to use the

  • Error: arithmetic over / underflow - divided by zero?

    Hello

    IM newbie on Adobe LiveCycle. Ive was able to create a form and now I tried to make some calculation about it.

    All right, the pdf is the calculation, but Im getting an error, because I understand that I'm trying to calculate with the classified, those that are empty - no need to register again as a field of zero = > divide by zero...?

    Can someone please help me, how to write the formula to get no errors?

    My actual formula is:

    pod11. RawValue = (((pod2.rawValue * (pod8.rawValue / 100)) - pod6.rawValue) / pod2.rawValue) * 100

    Thank you very much for the help!

    K.

    Hello

    to avoid errors to the breast to calculate that each field to ensure there is no rawValue is equal to null, you need to check...

    If you use formcalc, use "<>" or "no" to specify not equal to

    If you do not use javascript, use «!» = « ou » ! ==' to specify not equal to

    JavaScript

    If (pod2.rawValue! = null & pod8.rawValue! = null & pod6.rawValue! = null) {}

    pod11. RawValue = (((pod2.rawValue * (pod8.rawValue / 100)) - pod6.rawValue) / pod2.rawValue) * 100;

    } else {}

    pod11. RawValue = null;

    }

    FormCalc

    If (pod2.rawValue <> null & pod8.rawValue <> null & pod6.rawValue <> null) then

    pod11. RawValue = (((pod2.rawValue * (pod8.rawValue / 100)) - pod6.rawValue) / pod2.rawValue) * 100

    on the other

    pod11. RawValue = null

    endif

    I hope this will help you!

  • Rename the bookmarks using JavaScript?

    Hi all

    I searched the internet and Adobe forums and I can't find an answer to this. Is it possible to rename a bookmark using JavaScript? I want to run a batch renaming on my favorites to change or replace employees of employee names. For example:

    12345678 > John Doe

    I have to do this on a large amount of files that contain a large number of employee numbers and that's why I'm looking for a JavaScript solution. Thank you for all your help.

    There are different ways you can read an external file. It can be done using an object DataObject or even util.readFileIntoStream (), if the file is not too long.

    Once the contents of the file as a string you will need to process this string, divided by lines and then divide each line to get the data you need in a usable format.

    Then, you would need browse Favorites, by comparing each element in it the values in the list of the text file and rename it if it is a match.

    If the Favorites tree is not flat (that is to say, it has bookmarks under) you must use a recursive method to traverse it.

    This isn't a simple project for a beginner...

  • Divide total logic problem


    I have trying to subract a value of a total and then dividing this total to find out how many questions a person wrong (each question is assigned a value of 4)

    and I can't seem to wrap my head around the plain English script, I need to use. I know its staring me in the face.

    var DEDUCTION = this.getField("TOTAL").value;
    If (TOTAL = 100) event.value = "0";

    ElseIf (< 100 TOTAL) event.value = TOTAL - 100 /-4;

    It always shows 0. I turned off my rockers think it correct script?

    JavaScript syntax has different operators to assign a value and operators of comparison...

    The '=' is a simple assignment operator. There are other operators adding, subtracting, multiplying, dividing and assigning the rest by another value, as well as the bit assignment operators.

    The "is" is the simple value comparison operator. There are additional comparisons for Boolean comparisons.

  • JavaScript for the sum of a column cells

    Hi all -

    I have a table in expansion (lines can be added) and I am using the line of the column footer to calculate the average of the cells which do not have the value 0.

    Form Calc is usually great, but in this case, I need to divide the sum by the number of cells that are not zero and I don't know how to do this via form Calc.

    Successfully used javascript to identify the total number of occurrences and identify the number of instances that are zero, then the part of the denominator of the equation is fine. (Number of cases - number of zeros = denominator.)

    Now, it's just the numerator. There must be a loop, right?

    Is called table: table1

    Line is called: data

    cell is called: rated

    Any thoughts? Or more effective methods? Thank you very much.

    B

    Hello

    a solution in FormCalc could look this way:

    form1.#subform[0].table1.footer.sum::calculate - (FormCalc, client)
    var c = 0
    var s = 0
    for i = 0 upto (_data.count - 1) do
      if (data[i].eValue gt 0) then
      c = Sum(c, 1)
      s = Sum(s, data[i].eValue)
      endif
    endfor
    
    if (s gt 0 and c gt 0) then
      $ = Round(s / c)
    else
      $ = 0
    endif
    

    Put this scriot in the calculate of the cell of the footer line event.

  • ExternalInterface call the Javascript to AS2 array throwing error undefined

    I need to pass various (follow-up) IDs to a .swf.  the IDS are in a table like this =

    < script type = "text/javascript" >

    function getImpID() {}

    var medID = {impID: pvID '12345': ' 677890', exID: '654332'};

    return medID;

    };

    function thisMovie (banner) {}

    If (navigator.appName.indexOf ("Microsoft")! = - 1) {}

    Returns the window [banner]

    }

    else {}

    return the document [banner]

    }

    }

    Window.OnLoad = getImpID;

    < /script >

    For now, the AS2 I is:

    flash.external import. *;

    System.security.allowDomain (sourceDomain)

    var allID:String = ExternalInterface.call.apply ("getImpID");

    function getIDs() {}

    var impID:Number;

    var pvID:Number;

    var exID:Number;

    var id_arr:Array = allID.split(",");

    _root.id_test. Text = impID;

    }

    getIDs();

    Basically, what I need is to divide the three identifiers from the javascript so that I can add with different URL clickTags in the will.  I primarily the "undefined" error, so I'm going out on a limb here I have the AS2 does nothing now value.  More big scratcher head for me is, if I have the ID in an array in javascript (medID) how do I get them not only correctly in Flash, but separate them in their separate identity papers.

    Any suggestions would be greatly appreciated.

    Thank you!

    I forgot to answer, your tips have helped solve the puzzle =

    ActionScript:

    function idTag() {}

    getID = Object (ExternalInterface.call("saveglobalscore",score) ("getImpID"));

    getID.toString ();

    _root.id_test. Text = getID;

    }

    idTag();

    JavaScript

    has worked like a charm!

  • Division of JavaScript calculations

    I have sucessfully added values of the 6 groups of radio button in my form (using the script below) and I now want to divide by 6 to get the average before the result is displayed in the field. Can someone tell me what to add the script to do this? I'm a novice at Javascript and depend on this forum to help me who I want to say thank you for. This forum has seen me through a lot of project tasks asked of me.

    parseInt (Strategic.Strategic1.rawValue)

    + parseInt (BusKnowledge.Knowledge.rawValue)

     

    + parseInt (Compliance.Compliance1.rawValue)

    + parseInt (Decision.Decision1.rawValue)

    + parseInt (Demeanor.Demeanor1.rawValue)

     

    + parseInt (Relationships.Relationships1.rawValue);

    Hello

    FormCalc is delivered with an average function that you can use.

    Just put this script to calculate the field event to display averages:

    Avg(Strategic.Strategic1.rawValue, BusKnowledge.Knowledge.rawValue, Compliance.Compliance1.rawValue, Decision.Decision1.rawValue, Demeanor.Demeanor1.rawValue, Relationships.Relationships1.rawValue)
    
  • Question of Division of JavaScript

    I'm totally ignoring how to write JavaScript and very much appreciate the scripts in this forum. I used the following to calculate the value of six radio button groups and now before the show of the calculated value in the numeric field I want to divide by 6 to get the average value. Haven't found anything like that, but who works and appreciate it really help with this simple math problem.

    parseInt (Strategic.Strategic1.rawValue)

    + parseInt (Busknowledge.Knowledge.rawValue)

    \\etc. for the rest groups\\ 4

    ;

    You can use the LiveCycle forums.

    Do you know how to access and modify the field object in LiveCycle Designer?

    Have you looked at the LiveCycle Docuementation?

  • Formula for dividing the three entries from field (D = A/B/C)

    I have a formula to get a value, and this is to divide the three entries from field. I don't know enough about javascript to correctly enter the code to make this happen. I have 20 rows in a form and I need to calculate column D I saw a thread on how to divide the two fields, but I need to go further with it. Can someone help me? I added that I was working (left) and I tried to develop (right).

    Internet Personal

    establish the variables for the names of fields for the dividend and the divisor.

    var sDividend = ' domain name my dividends. "

    var sDivisor = 'name of the My divisor field. "

    get the value of the divisor field

    var nDivisor = this.getField ("sDivisor") .value;

    get the value of the dividend field

    var nDividend = this.getField('sDividend').vlalue;

    do not modify the code under this line

    Clear the value of the result field

    Event.value = ";

    see if we have a divisor of zero

    If (nDivisor! = 0) {}

    We can then divide

    Event.Value = nDividend / nDivisor;

    } / / end of calculation of the division

    The above assumes that you are dividing the value of the 2 fields.

    Assignment of the variables

    var PW1 = "PlotWt1";

    var WBC1 = "WetbuConversion1";

    var AF1 = "Acre Factor1";

    Get the values

    var nPW1 = this.getField (PW1) .value;

    var nWBC1 = this.getField ("WBC1") .value;

    FNa1 var = this.getField (AF1) .value;

    Clear the value of the result field

    Event.Value ="";

    see if we have a divisor of zero

    If (nWBC1! = 0) {}

    //Actual division operation

    event.value = nPW1 / nWBC1 / FNa1;

    } / / end of the calculation of the division

    Change the line of code:

    If (nWBC1! = 0 & nAFN! = 0) {}

    If you want to use the same calculation for a number of lines, you can create a function that all calculated fields can use, but it depends on the names of the fields that you use. If you are simply changing the number at the end, the function might be:

    function calc1(num) {
    
        // Assigning the variables
        var PW = "PlotWt" + num;
        var WBC = "WetbuConversion" + num;
        var AF = "AcreFactor1" + num;
    
        // Getting the values
        var nPW = this.getField(PW).value;
        var nWBC = this.getField(WBC).value;
        var nAF = this.getField(AF).value;
    
        // clear the result field value
        event.value="";
    
        // see if we have a non-zero divisor
        if (nWBC !=0 && nAF != 0) {
            //Actual division operation
            event.value = nPW / nWBC / nAF;
        }
    
    }
    

    You can then call it in the custom calculation of the field as the script:

    Calc1 (1);  Rank 1

    For line #5, it would be:

    Calc1 (5);  Rank 5

    This could be simplified a bit if you have changed your domain naming scheme to make it easier to extract the line number. In this way, that you wouldn't have to pass as I showed.

    To create a script at the level of the document to place the function, select: Advanced > Document Processing > Document JavaScripts > Add

  • If/then JavaScript help needed

    Hello

    I'm trying to write a script for a PDF in Adobe Acrobat form, but I don't have much experience with JavaScript and I need help!

    Basically, I have five fields as follows:

    A1 = a checkbox

    B1 = a field with a numeric value in it

    C1 = one field with a numeric value in it

    D1 = a field with a numeric value in it

    E1 = a field where calculation of the sum.

    I want to write a script that will enter into the sum of the values of B1 + C1 + D1 E1 if a1 is checked yes.

    If it is not checked yes, then he enters the sum of the values of B1 + C1 + D1 value by 2 (and rounded down) divided in E1.

    Can anyone help?

    Thank you!

    This should do it like the custom for E1 calculation script:

    // Custom calculate script
    (function () {
    
        // Get the field values, number fields as numbers
        var a1 = getField("A1").value;
        var b1 = +getField("B1").value;
        var c1 = +getField("C1").value;
        var d1 = +getField("D1").value;
    
        // Set this field (E1) value based on the state of the check box
        if (a1 === "Off") {
            event.value = b1 + c1 + d1;
        } else {
            event.value = b1 + c1 + Math.floor(d1 / 2);
        }
    
    })();
    
  • Divide an A3 page 2 A4s

    Hello!

    I am a journalist, and after the publication of the magazine, my publisher sent me my articles in pdf format to use in my portfolio.

    The problem is, when the article is more than a single page, they send me PDF files as well as 2 pages as a A3 instead of two A4s, if you wish. I searched through all the menus in Acrobat trying to figure out how just divide the page in the middle and make two pages out of it, but I can't understand it.

    I guess I could go through several stages of cropping, to create new documents of their merger... etc - but I'm sure that there is a faster way!

    Any help would be most appreciated!

    Thank you very much

    PS: If you need to see what I mean, check out my portfolio on issuu - the first two pages are A4s, then suddenly I get A3s: http://issuu.com/princesskarlotta/docs/art_film

    Post edited by: missphotographer

    Acrobat can do, but this isn't a feature with a simple user interface - you have to write a reasonably complicated JavaScript and, of course, a lot of people who write that these scripts do for a job, so need to charge for their products. If you spend enough time reading about Acrobat scripts you can write a script yourself 'for free', but the time it would take probably more worth for you.

    What if all you want to do is view or print the PDF file, just re-FRY (print from Acrobat to the Adobe PDF printer, select the page "Mosa∩que pages" scale and take portrait A4 as the size of the paper, so your page A3 is divided between two sheets). The file you create will lose any accessibility tags, layers, video, comments etc but it will cost you nothing to do.

    If you have Adobe Illustrator, you can open the file PDF and re-export there from there, page split using work plans. Once again, he will lose all of your interactive features, comments, etc. tag structure but would preserve the layers, unlike a re-do FRY.

Maybe you are looking for

  • Need information about HDD upgrade on Equium A100-027

    HI people :-) Can I change the HARD disk drive in my Equium a100 027 for one with a speed of 7200 RPM? If not what is the largest size of HARD drive I can put in? It is also useful to do a lot to make a dual boot with Vista and XP or get one with Vis

  • How can I get my SPACEBAR to stop acting like a scroll down button?

    I played a little flash game from the internet in Windows Explorer and sort, I pressed something on the keyboard that made my space bar turn into a scroll down button.  I tried to restart the computer, but it did nothing.  I have no idea of what I've

  • How to change the Administrator status

    How can I change the status of administrator on my Vista laptop?  I want Uninstal programs that I suspect even cause problems, but he says that I don't have Administrator status and contact the system administrator.

  • Where to download Windows Vista Italian?

    My client to have Windows Vista Italian, finally he left the original CD to the Italy, so where I can download Windows Vista full in Italian? Thank you

  • Is it possible to open a blackberry app by calling a URL or a hyperlink click on...

    I had crossed the CHAP method and special criteria but the corresponding model works only with the content typed on a textfield... My application works in coordination with the network and had open the application from a link, we encounter similar ty