Skip to content

Running Delayed Scripts at OnLoad

A major issue with running any sort of script from OnLoad is that we can't always rely on a specific target element actually being in place on the page at the time of the OnLoad ruleset. Many components have a delayed loading sequence, so don't appear on the page for several seconds.

So if the developer has coded to modify an element on the page directly within an OnLoad ruleset (eg a div element of id 'divTestX', $('#divTestX').text = 'hello world';), nothing may actually happen, because at the time this script runs, the target element does not yet exist on the page to modify.

To address this issue, there is a RulesetInclude, "Delayed Script JS". This RulesetInclude provides a method of running a javascript or jquery function on the page, from an OnLoad ruleset, but will wait until a particular element is available on the page before running.


A release document is currently available (2018-09-11) ¹

  • Save the attached file to your computer.
  • Run Template Editor on the target Formbird system
  • Upload the saved file; click Save.

(nb: please check if there is a later version available)

¹ nb: may not be available to all readers


  • Include the new ruleset include document in your OnLoad ruleset
#include "Delayed Script JS",    // provides object ft3.delayedScript 
  • To call, define the JQuery selector for the element you want to ensure is there, and script your function, using the method ft3.delayedScript.runDelayedFunction .


  //ft3.delayedScript.timeout = 5000;
  //ft3.delayedScript.maxTries = 8;

  ft3.delayedScript.runDelayedFunction(ntf, 'div#divTestX', function() {'divTestX now on the page');

    var $divTestX = $('div#divTestX');
    $divTestX.html('<b>this field is now changed</b>');


ft3.delayedScript.runDelayedFunction(ntf, selector, function() {

Part Description
selector A JQuery style selector string identifying the target element to wait for.
script-to-run Javascript or JQuery script to be run.


delayedScript.timeout = timeout-in-ms;

Set the required timeout in milliseconds. The function will stop checking if the target element is there after the set time.

delayedScript.maxTries = nbr-retries;

Set the maximum number of tries to find the target element. Each try takes 0.5 seconds.