Cannot add dynamically updated element to the database

I get text from the backend and manually set field’s value using javascript. But when this field is added to the database, it’s empty.
I’ve tried creating an invisible field, tried creating hook function, but I cannot pass the value from frontend to the hook function which is on the backend.
How can I resolve this issue and add that value to the database?

Are you using a dataset for your collection? If so, then you probably need to use setFieldValue() .

It worked, thank you