All input field types contain an onChange and onLoad area. In this area JQuery/Javascript code can be added which make it possible to use if-then-else formula's and create certain form actions based on user input.


onChange scripts: The code/action will be executed when input is entered or changed in the field


onLoad scripts: The code/action will be executed when the form is opend.


Below are a few examples of actions with code which can be used in the forms.
 

Jquery/Javascript is a very common programming language and is well documented on the following websites:

Javascript: https://www.w3schools.com/js/default.asp

JQuery: https://www.w3schools.com/jquery/default.asp




Example onChange Scripts



Copy a entered value to another field


Field 1: tf_field_1

Field 2: tf_field_2 


Paste the following code into the onChange Script area of tf_field_1


$('#tf_field_2').val($('#tf_field_1').val());


This will pre-fill tf_field_2 with the value of tf_field_1





Merge the text of two fields together


Field 1: tf_field_1

Field 2: tf_field_2 

Field 3: tf_field_3



Paste the following code into the onChange Script area of tf_field_1 and tf_field_2



$('#tf_field_3').val($('#tf_field_1').val() + ' ' + $('#tf_field_2').val());


This will pre-fill tf_field_3 with the value of tf_field_1 plus a space and the value of tf_field_2








Add the results of two fields together 


Field 1: tf_field_1

Field 2: tf_field_2 

Field 3: tf_field_3


Paste the following code into the onChange Script area of tf_field_1 and tf_field_2 :



$('#tf_field_3').val(($('#tf_field_1').val()*1) + ($('#tf_field_2').val()*1));


This will pre-fill tf_field_3 with sum of tf_field_1 plus tf_field_2 







Subtract the values of two fields


Field 1: tf_field_1

Field 2: tf_field_2

Field 3: tf_field_3

Paste the following code into the onChange Script area of tf_field_1 and tf_field_2



$('#tf_field_3').val(($('#tf_field_1').val()*1) - ($('#tf_field_2').val()*1));


This will pre-fill tf_field_3 with the value tf_field_1 minus the value of tf_field_2 






Example onLoad Scripts



Pre-fill the current users name


Field 1: tf_field_1

Current username: TF_USER


Paste the following code into the onLoad Script area of tf_field_1


if ($('#tf_field_1').val() == '') {$('#tf_field_1').val(TF_USER);}


If tf_field_1 is empty the name of the current user will be entered





Pre-fill the current user e-mailaddress


Field 1: tf_field_1

Current user e-mailaddress : TF_USER_EMAIL


Paste the following code into the onLoad Script area of tf_field_1


if ($('#tf_field_1').val() == '') {$('#tf_field_1').val(TF_USER_EMAIL);}


If tf_field_1 is empty the name of the current users e-mailaddress will be entered





Pre-fill the current document name


Field 1: tf_field_1

Current document name: TF_DOCUMENTNAME


Paste the following code into the onLoad Script area of tf_field_1


if ($('#tf_field_1').val() == '') {$('#tf_field_1').val(TF_DOCUMENTNAME);}


If tf_field_1 is empty the current document name will be entered





Pre-fill the current document number


Field 1: tf_field_1

Current document number: TF_DOCUMENTNR


Paste the following code into the onLoad Script area of tf_field_1


if ($('#tf_field_1').val() == '') {$('#tf_field_1').val(TF_DOCUMENTNR);}


If tf_field_1 is empty the current document number will be entered





Pre-fill the current date


Field 1: tf_field_1

Current date in a date input field: DATE 

Current date in a text input field: date 



Paste the following code into the onLoad Script area of tf_field_1


if ($('#tf_field_1').val() == '') {$('#tf_field_1').val(DATE);}




If tf_field_1 is empty the current date will be entered