Javascript change value to input field not being recorded in inbox

Question:
Why is it that when I use javascript to change teh value of an input field it changes on the front end and when the form is submitted the field doesn’t record anything

Product:
I am using the wix editor on the homepage

What are you trying to achieve:
I am trying to capture the referrer information in the script and add it to a hidden input field

What have you already tried:
The code I use is

	import wixWindowFrontend from 'wix-window-frontend';
	let referrer = wixWindowFrontend.referrer;
	
$w.onReady(function () {
	let nreferrer = referrer.toString();		
	$w('#input7').value = nreferrer;
	console.log(referrer.toString());// Write your JavaScript here
	console.log($w('#input7').value);// Write your JavaScript here
});

Additional information:
The console logs the right information, yet it still doesn’t add the information to the inbox form.

Is the field connected to a dataset? According to the docs setting the value won’t change what is submitted when the form is submitted and you’ll need to call setFieldValue() before submit.

This is because the dataset is what gets submitted.

Hi,

The form is not connected to a dataset. if I make the change like

$w('#input7').value = "https://somesite.com";

The change sticks and is visible in the inbox and goes through to the CRM.

if I use setFieldValue() I get an error.

I have found the proper method of doing this. Just in case someone in the future needs to do something similar

Use the onWixFormSubmit so when the form is submitted it will include the data

$w("#wixForms1").onWixFormSubmit((event) => {
    var nreferrer = referrer.toString();
    $w('#input7').value = nreferrer;
});
1 Like