How to capture the onchange event of a relate field.

Hello All,

I have the following code:

document.getElementById(“field_name”).addEventListener(“change”, functiontocall);

to capture the onchange event of a relate field. But this captures the present value and not the changed value. I cannot understand how do I capture the changed value when the value in the relate field changes. Kindly help.

Thank you.

Any idea.


Did you find what event relate field uses?

Thank you.

Do you really want to capture this as a browser event, or would you rather capture it in a logic hook (like after-Save) where you can easily manipulate all the data? It depends on what you’re trying to accomplish, but I just want to make sure you know about logic hooks…

To have onchange for a relate field I use the following code in editview.defs

0 => array (
	'name' => 'zz_css_job_name',
	'label' => 'LBL_ZZ_CSS_JOB_NAME',
	'tabindex' => '3',
	'displayParams' => array (
		'field' => array (
		'onblur' => 'GetAccount()' 
	'javascript' => array (
		'btn' => ' onblur="GetAccount()" ',
		'btn_clear' => ' onblur="GetAccount()" ' 

The function then picks up the changed id

1 Like

Hi Mike,

I used blur event but after select on relate field it just trigger when click anywhere on screen, it is inconvenient.

Do you have any idea?

This can be solved by hooking popup window close.
Use inspect element to find ids of input field and its buttons.


$(document).ready(() => {
	let onRelateChanged = () => {
		// related object value is stored in hidden field
		console.log($('#<field name>_ida').attr('value'));

	// hook popup window open (pointer icon button)
	$('#btn_<field name>_name').on('click', () => {
		// hook popup close
		win.onbeforeunload = () => {
			setTimeout(onRelateChanged, 100); // small delay here because window closes first
	// hook relation reset (close icon button)
	$('#btn_clr_<field name>_name').on('click', onRelateChanged);
	// input field
	$('#<field name>_name').on('change', onRelateChanged);
1 Like