Page 1 of 1

code to calculate strings into a field

Posted: Fri Aug 14, 2020 2:58 pm
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

Re: code to calculate strings into a field

Posted: Fri Aug 14, 2020 3:01 pm
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"

Re: code to calculate strings into a field

Posted: Fri Aug 14, 2020 3:05 pm
by kev1n
Or with pure Javascript, this should work too:

Code: Select all

cli_easycode.value = all;
cli_easycode.classList.add("nuEdited");

Re: code to calculate strings into a field

Posted: Fri Aug 14, 2020 6:14 pm
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!

Re: code to calculate strings into a field

Posted: Fri Aug 14, 2020 6:18 pm
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!

Re: code to calculate strings into a field

Posted: Fri Aug 14, 2020 6:30 pm
by kev1n
PS: You'll need to import the sample into a new nuBuilder database.