Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

concatenation

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
JEDV
Posts: 9
Joined: Sat Oct 06, 2018 8:55 pm

concatenation

Unread post 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?
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: concatenation

Unread post 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.
JEDV
Posts: 9
Joined: Sat Oct 06, 2018 8:55 pm

Re: concatenation

Unread post 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.
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: concatenation

Unread post by kev1n »

correction of the js code:

Code: Select all

 field3.value = field1.value + " " + field2.value; var event = new Event('change'); field3.dispatchEvent(event);
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: concatenation

Unread post by admin »

.
JEDV
Posts: 9
Joined: Sat Oct 06, 2018 8:55 pm

Re: concatenation

Unread post 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);
Post Reply