Auto-Populate Form Custom Fields with Custom JS
Use a small JavaScript snippet to populate Sparkforge form custom fields with dynamic data and have the value persist on submit.
You can auto-populate any custom field on a Sparkforge form or survey with a short JavaScript snippet. The value gets captured in the submission like any user-entered field.
Find the custom field ID
- Open the form in Preview.
- Right-click the page and select Inspect.
- Use the element picker tool.
- Click the custom field input.
- Copy the value from the
name/idattributes.
Example: if your custom field is named xxTrustedFormCertUrl, follow the steps above to retrieve its DOM ID.
Set the value with JavaScript
Replace myData with the variable holding your captured value, and replace customFieldId with the ID you copied.
document.getElementsByName('customFieldId')[0].value = myData;
document.getElementsByName('customFieldId')[0].dispatchEvent(new Event("input"));The input event is critical — without dispatching it, the form won't register the change and the value won't be captured on submit.
Frequently Asked Questions
Why doesn't my value save without dispatching the input event?
Sparkforge forms watch for input events to detect changes. Setting .value alone doesn't trigger that listener, so the field looks empty at submit time.
Where does this JavaScript go?
Add it to the page hosting the form — for example, in a Custom HTML/JavaScript element on a funnel or website page.
Can I populate multiple custom fields with one script?
Yes. Repeat the two lines for each field, replacing the field ID and the data variable.
Will the value show in the form submission record?
Yes. As long as the input event was dispatched before submit, the populated value is captured in the submission like a manually entered field.
Was this article helpful?
Thanks for the feedback.