# JavaScript

Currently Being Moderated

## need help with creating a formula for percentages

### Aug 16, 2012 8:27 AM

I am creating a fillable form for subcontractors to submit change requests. One of the sections on the form is for materials. Most subs will charge a markup which is a small percentage of the actual cost. Obviously, both amounts are variables. I want the subs to be able to enter the material cost in field 1, the markup percentage in field two, and then have field three calculate the dollar amount for them. Is this possible? Btw, I'm clueless on this, it's my first attempt at an adobe form. Thanks!!!

Replies
• Currently Being Moderated
Aug 23, 2012 1:49 AM   in reply to sschmitz63

Add the following script in field 3 onfocus.

var a=this.getfield("field1").value;

var b=this.getfield("field2").value;

var c=a*b/100; (calculation only for example; include your calculation)

this.getfield("field3").value=c;

Also please set the properties for filed 3 like mentione below:

format                  : Number

Decimal places     : 2

Currency Symbols : Dollor (\$)

|
Mark as:
• 10,288 posts
Aug 11, 2002
Currently Being Moderated
Aug 23, 2012 3:52 PM   in reply to sschmitz63

A more standard way is to use something like the following as the third field's custom Calculate script:

// Custom calculate script

(function () {

// Get the field values, as numbers

var v1 = +getField("price").value;

var v2 = +getField("markup_percentage").value;

// Calculate the value of this field

event.value = v1 * (1 + v2 / 100);

})();

This is assuming that a percentage of 20% is entered by the user as 20, as opposed to 0.2 or something else. Change the field values to match the actual fields in your form.

If the markup field is blank or zero, the total will simply be the same as the price value.

|
Mark as:
• Currently Being Moderated
Sep 27, 2012 10:27 AM   in reply to sschmitz63

I really need help too!!!

I'm creating a form that needs to tally the score (on a scale of 1-5) given in several text fields, divide it by the total score possible (55) and display it at the bottom of the page as a percentage. Can anyone please please help me?! I'm a javascript dunce. I tried applying the above scripts but to no avail. Any assitance would be much appreciated.

|
Mark as:
• Currently Being Moderated
Sep 27, 2012 3:18 PM   in reply to racincos

|
Mark as:
Actions

#### More Like This

• Retrieving data ...

#### Answers + Points = Status

• 10 points awarded for Correct Answers
• 10,000+ points
• 1,001-10,000 points
• 501-1,000 points
• 5-500 points