Fill a Custom Field Automatically With a Short Script

If another tool produces a value on your page, such as a certificate link or a campaign code, you can place it into a form field so it saves with the submission.

Find the field's ID

  1. Open the form's Preview.
  2. Right-click the page and choose Inspect.
  3. Use the pointer tool in the developer panel and click the custom field.
  4. Copy the value of its name and id attributes.

Add the script

  1. In the builder, drag an HTML element onto the form.
  2. Click Edit HTML.
  3. Paste a script like this, replacing FIELD_ID and myValue with your own:

document.getElementsByName('FIELD_ID')[0].value = myValue; document.getElementsByName('FIELD_ID')[0].dispatchEvent(new Event('input'));

  1. Save and test.

The second line tells the form that the field changed, so the new value is submitted along with everything else.

Tips

  • Make sure the script runs after the value exists and after the form has loaded.
  • Confirm the value appears in Sites > Forms > Submissions and on the contact.
  • Hidden or read-only fields work well for this.

Remember the HTML editor blocks scripts that read cookies or localStorage.

Good to know: Test with a live submission, not just the preview, since values from outside tools may only exist on the published page.

Was this article helpful?