Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Dynamic URL in HTML object Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
Paul
Posts: 31
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 9 times
Been thanked: 1 time

Dynamic URL in HTML object

Unread post by Paul »

Desired outcome:
Depending on what the user enters into 'pk_AutoLyseDuration' field, change the URL in 'AutoLyse Timer URL' (pk_AL_TimerURL). 'AutoLyse Timer URL' needs to be a clickable URL.
AutoLyseTimer.PNG
Here is 'pk_AL_TimerURL' so far:

object: pk_AL_TimerURL

onchange event:
const AutoLyseMap = {
'.5': 'http://localhost/recipes/30-minute-timer/',
'1': 'http://localhost/recipes/timer/',
'2': 'http://localhost/recipes/2-hour-timer/',
'3': 'http://localhost/recipes/3-hour-timer/',
'4': 'http://localhost/recipes/4-hour-timer/',
'5': 'http://localhost/recipes/5-hour-timer/',
'6': 'http://localhost/recipes/6-hour-timer/',
'7': 'http://localhost/recipes/7-hour-timer/',
'8': 'http://localhost/recipes/8-hour-timer/',
};

const name = nuGetValue('pk_AutoLyseDuration'); //
nuSetValue('pk_AL_TimerURL', urlMap[name] || ''); //

What would I enter into the HTML area to accomplish the desired outcome?
You do not have the required permissions to view the files attached to this post.
Last edited by Paul on Thu Sep 11, 2025 4:34 am, edited 1 time in total.
steven
Posts: 387
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 57 times
Been thanked: 53 times

Re: Dynamic URL in HTML object

Unread post by steven »

Hi Paul,

If you are familiar with JavaScript and/or jQuery,

you can use their functions to change different elements...

Code: Select all


const url = '<a href="' + $('#pk_AutoLyseDuration').val() +'">' + ' Click Me.</a>'';

$('#pk_AutoLyseDuration').html(url);


Steven
A short post is a good post.
Paul
Posts: 31
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 9 times
Been thanked: 1 time

Re: Dynamic URL in HTML object

Unread post by Paul »

When I place your code into the HTML tab of pk_AL_TimerURL, I get this on the form:
ALTimerLink.PNG
The link in the status bar is:
http://localhost/nubuilder/'+%20$('#pk_ ... ).val()%20+'
You do not have the required permissions to view the files attached to this post.
steven
Posts: 387
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 57 times
Been thanked: 53 times

Re: Dynamic URL in HTML object

Unread post by steven »

Paul,

That code goes on the on blur event of your element pk_AutoLyseDuration.

Not in the HTML.


Steven
A short post is a good post.
Paul
Posts: 31
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 9 times
Been thanked: 1 time

Re: Dynamic URL in HTML object

Unread post by Paul »

Not sure if you understand my intended result. Re-read my original post?
kev1n
nuBuilder Team
Posts: 4456
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 494 times
Contact:

Re: Dynamic URL in HTML object

Unread post by kev1n »

How about this? (Place it in the onblur or oninput event of pk_AutoLyseDuration)

Code: Select all

const AutoLyseMap = {
    '.5': 'http://localhost/recipes/30-minute-timer/',
    '1': 'http://localhost/recipes/timer/',
    '2': 'http://localhost/recipes/2-hour-timer/',
    '3': 'http://localhost/recipes/3-hour-timer/',
    '4': 'http://localhost/recipes/4-hour-timer/',
    '5': 'http://localhost/recipes/5-hour-timer/',
    '6': 'http://localhost/recipes/6-hour-timer/',
    '7': 'http://localhost/recipes/7-hour-timer/',
    '8': 'http://localhost/recipes/8-hour-timer/',
};

const url = nuComposeURL(AutoLyseMap[this.value] || '', 'Click Me');
nuSetValue('pk_AL_TimerURL', url, 'html');
Paul
Posts: 31
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 9 times
Been thanked: 1 time

Re: Dynamic URL in HTML object

Unread post by Paul »

Putting that in the onInput event worked. Excellent! Thank you, Kevin!
Paul
Posts: 31
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 9 times
Been thanked: 1 time

Re: Dynamic URL in HTML object

Unread post by Paul »

It works, but the link dissappears when I save the record. I'd like to be able to save the html and then overwrite it (if there are changes) each time the record is saved.
kev1n
nuBuilder Team
Posts: 4456
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 494 times
Contact:

Re: Dynamic URL in HTML object

Unread post by kev1n »

HTML elements are not stored in the database (they are display-only objects).

One option is to call setTimerURL() both in the pk_AutoLyseDuration change event and in the form’s Custom Code when the form is loaded.

Code: Select all

function setTimerURL() {

	const AutoLyseMap = {
		'.5': 'http://localhost/recipes/30-minute-timer/',
		'1': 'http://localhost/recipes/timer/',
		'2': 'http://localhost/recipes/2-hour-timer/',
		'3': 'http://localhost/recipes/3-hour-timer/',
		'4': 'http://localhost/recipes/4-hour-timer/',
		'5': 'http://localhost/recipes/5-hour-timer/',
		'6': 'http://localhost/recipes/6-hour-timer/',
		'7': 'http://localhost/recipes/7-hour-timer/',
		'8': 'http://localhost/recipes/8-hour-timer/',
	};

	const url = nuComposeURL(AutoLyseMap[nuGetValue('pk_AutoLyseDuration')] || '', 'Click Me');
	nuSetValue('pk_AL_TimerURL', url, 'html');

}
Post Reply