Page 1 of 1
concatenation
Posted: Wed Oct 24, 2018 3:45 pm
by JEDV
I am trying to concatenate two string fields into a third string field on a add form using custom code in the object of a form.
object field2
event onblur [of field2]
javascript field3.value = field1.value + " " + field2.value;
This works beautifully and field3 displays the concatenated value on the form. However, on saving the record, the field3 value is not saved. Could someone point me to a source that would explain how to do this correctly?
Re: concatenation
Posted: Wed Oct 24, 2018 3:57 pm
by kev1n
You need to trigger the change event.
With pure JavaScript:
Code: Select all
var event = new Event('change'); element.dispatchEvent(event); field3.value = field1.value + " " + field2.value;
Or event shorter with jQuery:
Code: Select all
$('#field3').val($('#field1').val() + " " + $('#field2').val()).change();
This will add the class nuEdited to the field3. Only fields that have this class will be saved to the DB.
Re: concatenation
Posted: Wed Oct 24, 2018 11:18 pm
by JEDV
Thanks Kevin. The Jquery worked great. The pure JavaScript did not, but I likely did not understand it. Time to work thru a JavaScript and jquery tutorial.
Re: concatenation
Posted: Wed Oct 24, 2018 11:22 pm
by kev1n
correction of the js code:
Code: Select all
field3.value = field1.value + " " + field2.value; var event = new Event('change'); field3.dispatchEvent(event);
Re: concatenation
Posted: Thu Oct 25, 2018 3:51 am
by admin
.
Re: concatenation
Posted: Sat Feb 09, 2019 8:21 pm
by JEDV
Kevin,
In order to get your JavaScript above to work I had to change the variable name "event" to event1. I suspect that "event" is a reserved word.
field3.value = field1.value + " " + field2.value; var event1 = new Event('change'); field3.dispatchEvent(event1);