Skip to Content
FeaturesFormsJavaScript Actions

JavaScript Actions

Add custom form logic with JavaScript.

Form creation requires a Pro plan or higher. Form filling is available on all plans.

JavaScript in Forms

Penvio supports JavaScript for:

  • Field calculations
  • Validation
  • Dynamic behavior
  • Custom actions

Event Types

Field Events

  • On Focus: Field receives focus
  • On Blur: Field loses focus
  • On Change: Value changes (after entry)
  • On Keystroke: Each key press
  • Calculate: When calculations run
  • Validate: When validating input
  • Format: When formatting display

Document Events

  • Document Open: When PDF opens
  • Document Close: When PDF closes
  • Document Save: Before saving

Page Events

  • Page Open: When page is displayed
  • Page Close: When leaving page

Adding JavaScript

To a Field

  1. Open field properties
  2. Go to Actions tab
  3. Select event type
  4. Choose Run JavaScript
  5. Enter your script

Document-Level

  1. Click FormsDocument Scripts
  2. Add functions available throughout the document
  3. Call from field scripts

Common Scripts

Show/Hide Fields

// Hide a field this.getField("fieldName").display = display.hidden; // Show a field this.getField("fieldName").display = display.visible;

Set Field Value

this.getField("targetField").value = "New Value";

Get Field Value

var value = this.getField("sourceField").value;

Validation

// In validate event if (event.value.length < 5) { app.alert("Please enter at least 5 characters"); event.rc = false; // Reject change }

Format on Keystroke

// Allow only numbers if (event.willCommit) { if (isNaN(event.value)) { event.rc = false; } }

Conditional Logic

// Show field based on checkbox var isChecked = this.getField("checkbox").value === "Yes"; this.getField("extraInfo").display = isChecked ? display.visible : display.hidden;

Field Object Properties

PropertyDescription
valueCurrent field value
displayVisibility state
readonlyRead-only state
requiredRequired state
fillColorBackground color
textColorText color
borderColorBorder color

Utility Functions

Alert

app.alert("Your message here");

Confirm

var result = app.alert({ cMsg: "Are you sure?", nType: 2, // Yes/No buttons cTitle: "Confirm" }); if (result === 4) { // Yes clicked // proceed }

Calculate Total

var total = 0; for (var i = 1; i <= 5; i++) { var val = this.getField("item" + i).value; if (!isNaN(val)) total += Number(val); } event.value = total;

Tips

  • Test scripts thoroughly
  • Use meaningful field names
  • Handle errors gracefully
  • Comment complex logic
  • Keep scripts efficient

Next Steps

Last updated on