PDF Editing Issues

How to Automatically Fill a PDF Winner Field Based on Two Scores

Aamir Naveed AkramAamir Naveed Akram Nov 5, 2026 869 views

Question details

The user wants to automatically display a winning player's name in a PDF text field by comparing two respective score fields.

How to Automatically Fill a PDF Winner Field Based on Two Scores
Product
PDF
Device & OS
not provided
Scenario
Creating an interactive PDF form, such as a sports or gaming bracket, where the winner needs to be calculated and displayed automatically without manual entry.
Observed behavior
The goal is for the Winner text field to dynamically update with the text from 'Player1' or 'Player2' depending on whose score field has the higher number, and to remain blank if there is a tie.
Before you start

Ensure your PDF editing software supports JavaScript for interactive forms, and write down the exact field names for the players' names, scores, and the final winner field before starting.

Solution 1Recommended

Use a Custom Calculation Script in the Winner Field

Apply a short JavaScript code snippet to the winner field's calculate properties to automatically compare the two scores.

PDF forms can run JavaScript to perform dynamic calculations based on user input. By using a standard if/else logic (ternary operator) within the form's calculate tab, you can instantly populate the winner field.

1
Access field properties

Open your PDF form in a capable PDF editor. Right-click the text field designated for the 'Winner' and select 'Properties'.

2
Navigate to the calculation settings

In the Properties dialog box, go to the 'Calculate' tab.

3
Enter the custom script

Select 'Custom calculation script' and click the 'Edit' button. Paste the following code into the script editor: var p1 = Number(this.getField("p1score").value); var p2 = Number(this.getField("p2score").value); this.getField("winner").value = p1 > p2 ? this.getField("Player1").value : p2 > p1 ? this.getField("Player2").value : "";

4
Save and test

Click 'OK', close the properties window, and test your form by entering scores into the 'p1score' and 'p2score' fields. The winner field should automatically update.

Use a Custom Calculation Script in the Winner Field
Tie Scores Handled: The provided script includes logic to leave the winner field completely blank in the event that the scores are tied.
Edit Interactive PDFs Easily

Create and Edit Advanced PDF Forms with WPS Office

WPS Office provides powerful PDF editing tools, including the ability to create interactive forms and manage field properties. You can easily set up field calculations, checkboxes, and text inputs without needing expensive enterprise software.

  1. 1. Open your PDF: Launch WPS Office and open your existing PDF form document.
  2. 2. Access the Form tab: Navigate to the 'Form' tab on the top ribbon to access the interactive field tools.
  3. 3. Edit Field Properties: Double-click any text field to open its properties menu and configure formatting or calculations.
Easily insert text fields, checkboxes, and buttons to create fully interactive forms.Fully compatible with standard PDF forms and Adobe Acrobat form calculations.Lightweight software with an intuitive, user-friendly interface.Includes a rich suite of PDF editing, conversion, and annotation tools.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF calculation script not working?

Ensure that the field names used in your JavaScript (like 'p1score' or 'Player1') exactly match the actual field names you created in your PDF form. JavaScript is strictly case-sensitive.

Can I use this script for comparing more than two players?

The provided script is specific to two score fields. For multiple players, you would need a more complex JavaScript using an array and a Math.max function to determine the highest score among the group.

Do all PDF readers support JavaScript calculations?

Most robust desktop PDF readers support JavaScript in forms. However, some basic mobile PDF viewers, lightweight browser extensions, or default system preview apps might not execute these scripts properly.

How do I clear the winner field if the scores are deleted?

The script automatically handles empty score fields by treating them as zero. If both score fields are cleared (meaning they both equal zero), the script registers a tie and sets the winner field to empty.