Use Javascript in form

Hello,

I have a field called Latijnse_Naam and i want only the first character from each word in the string and put this outcome in a other field “trefnaam” after a ajax event . I made a javascript method: with a parameter field (latijn).

The Javascript method:
let shortname=latijn;
shortname=shortname.split(’ ‘).map(word=>word[0]).join(’’);

how can i set the field trefnaam with the value (shortname) form the Javascript method?

thanks

shortname should be in a variable ($shortname);
then:
{trefnaam}=$shortname;

Thank you for your answer.

When i set the variable ($shortname) in the Javascript method and i use alert($shortname) in the javascript methoh, then i see the right data.

But when i finish the ajax event with {trefnaam}=$shortname, nothing happend.?

It should be in an ajax “on change” event for latinjn field.

Thanks,

I have change the event to “on change” but the field {trefnaam} wil not be updated. Strange… because i have made a button in the toolbar with the alert($shortname) and after the on_change event this alert shows the right data?

But the field {trefnaam} stays empty?

Can’t think of anything else to try. Is it the right type of field? Is it read only?