Embed a form using JavaScript
A JavaScript code helps you to embed a form in your website as a part of your webpage. Unlike iframe, this option will embed the form as a page element and not as an external resource. You can choose to auto-resize or set custom height for your form using the JavaScript embed code.
Using the Default JS Code
This option allows a user to have contextual resizing of their form. Once this script is used, your form will be set to an initial height based on the visible fields in the first page of the form. As the user navigates through the form, it will resize dynamically based on the user action. The code snippet will automatically calculate the height of your form based on the visible fields in your form page.
To get the auto resizing JS code,
-
In your form builder, navigate to Share tab and click Embed in the left menu.
-
Click Javascript.
-
Under Default JS Code, click Copy Code.
-
Paste the copied code into the HTML of your website at the place where you want the form to appear on your page.
Customizing the JS Code
Set Fixed Height
You can set a fixed height for your form using this option. If your form is long, a scroll will be provided.
To use a customized
Javascript
code snippet to set a fixed height for your form,
-
In your form builder, navigate to the
Share
tab and click Embed
in the left menu.
-
Click Javascript and click
Customize Now.
-
Select Set Fixed Height
and enter the desired form height.
-
Click
Get Code,
then click Copy Code.
-
Paste the copied code to the HTML of your web page.
Include URL Parameters
You can include the following URL parameters using this option:
-
Referrer name : This helps you track the source from which the form was filled.

-
Field alias
: This helps you to prefill the form fields with predefined values.

Click
Get Code
and click Copy Code. Paste the copied code to the HTML of your web page.
Note: If you have already embedded the JavaScript code to your website and later choose to use custom height or include URL parameters for your form, make sure that you click
Copy Code
to copy the code generated after customizing the JS code. If not copied, you may end up using the code snippet for default auto-resizing. Replace the existing code with the copied code in your webpage.
Example:
On including the height and the width attributes:
If your embedded form has an Image Upload field, respondents will not be able to capture pictures using the webcam. To allow this, you must include the following in the embed code:
-
allow="camera"
-
?zf_enablecamera=true
For example:
When to prefer JavaScript code over iframe?
While choosing the provided iframe code to embed in your webpage, the height and width of the form is auto-calculated. This is an approximate value, hence there are chances of your forms not showing up correctly on your web page.
In such cases, we recommend you to use the JavaScript code, which will help you overcome the following issues:
-
Too much white space around your form
-
A part of the form gets cut-off on embedding
-
The form gets embedded with scroll bars
-
The scrolls vary depending on each page length making your form appear uneven
With the JavaScript code, your form dimensions are auto-calculated to fit the style of your webpage.