Welcome to the nuBuilder Forums!

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

code to calculate strings into a field

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
pbweb1969
Posts: 7
Joined: Sat Aug 08, 2020 12:13 pm

code to calculate strings into a field

Unread post by pbweb1969 »

I thought this would be easier than it seems to be!
im trying to take a date of birth and initials and create a unique code to also identify a client (for use by people). this is automaticly generated when adding the clients details.

the following code works, in that it puts the code into the easycode field (ive tried text input and textarea and calculated fields), but DOESNT save to the database UNLESS you go into the easycode field and edit it

after entering the persons date of birth, i used the customcode on event =onchange

var dobval = document.getElementById("cli_dob").value;
var doini = document.getElementById("cli_ini").value;
var dobstr = dobval.toString();
var dobday =dobstr.charAt(0)+dobstr.charAt(1);
var dobyr = dobstr.charAt(8)+dobstr.charAt(9);
var make =document.getElementById('cli_easycode').value;
var all=doini+dobday+dobyr;
cli_easycode.value = all;
cli_easycode.value = cli_easycode.value;

how do you get the stored value (which shows up in the field) to update the database? (ive tried a few different methods)

many thanks
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: code to calculate strings into a field

Unread post by kev1n »

You need to trigger the change event. I think it's easier with jQuery.

So, instead of

Code: Select all

cli_easycode.value = all;
Write:

Code: Select all

$('#cli_easycode').val(all).change();

nuBuilder only saves records that have a class of "nuEdited"
Last edited by kev1n on Fri Aug 14, 2020 3:12 pm, edited 1 time in total.
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: code to calculate strings into a field

Unread post by kev1n »

Or with pure Javascript, this should work too:

Code: Select all

cli_easycode.value = all;
cli_easycode.classList.add("nuEdited");
pbweb1969
Posts: 7
Joined: Sat Aug 08, 2020 12:13 pm

Re: code to calculate strings into a field

Unread post by pbweb1969 »

works a treat kev1n, thanks

BTW is there a video showing how the staff roster was created or is there a sample database?

I cant beleive a system as powerful and adaptable as this was sooo hard for me to find (ive been looking at software for months).
anything I can do to spread the word, let me know!
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: code to calculate strings into a field

Unread post by kev1n »

Some sample databases can be found here:

https://sourceforge.net/projects/nubuil ... databases/

pbweb1969 wrote: anything I can do to spread the word, let me know!
Yes please. Share it on social media, other forums, with friends etc!
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: code to calculate strings into a field

Unread post by kev1n »

PS: You'll need to import the sample into a new nuBuilder database.
Post Reply