how to set a value for the link element from php and js

smart

Member
I tried to find how to set a link value for a link element but couldn't find it yet.
For an element I know how to do those.
{table___element} or _raw would get /set data in php.
this.form.formElements.get('table___element').update or getvalue would do in js.

But I don't know the syntax to set/get value for the link.
Thanks

edit: If I use this.form.formElements.get('table___element').update, both label and link values are set.
 
Last edited:
I usually use calc element instead of link element which gives some extra possibilities for more complicated cases.
 
Thank you for your suggestion. But I maily want to use the smart media link feature to show audio/video/photo with the mediabox and link element is the only option. One suggestion from stack overflow is as follows. It works but some js warning showed up.

JavaScript:
  const [label, link] = [...document.querySelectorAll('#tk___kiaAlink input')];
  [label.value, link.value] = ['Audio', 'https://archive.org/download/' + AudioID + '/' + valS1];

I am still in learning process so I am not able to fix this yet.
 
That code is set on the form's element, Javascript, onChange event. Warning is below.
"Expected an identifier and instead saw '['. const '{a}' is initialized to 'undefined'. Missing semicolon. Bad assignment. I'll have to find out more for that warning.

Now the code has been modified to this
JavaScript:
document.querySelector('#tk___kiaVlink input:nth-child(2)').value = 'some string'

and it works.
 
This works for me without any errors:

Code:
jQuery("#mytable___mylinkelement input:first-child").val("label");
jQuery("#mytable___mylinkelement input:nth-child(2)").val("link");
 
Yes, you can use it the same way as you use Javascript as jQuery is a Javascript library to make things easier.
 
Thank you. Another question here. How could the link data (url) of the link element be retrieved or set in php code?
For field element,
PHP:
$formModel->getElementData('tk___kdescription');

But for link element, both label and link data could get. I guess I have to learn html tag/code structures to get the data.
 
Link element return array. so I am able to access 'link' by using this

PHP:
$formModel->getElementData('tk___kiaAlink')["link"]
 
This works for me without any errors:

Code:
jQuery("#mytable___mylinkelement input:first-child").val("label");
jQuery("#mytable___mylinkelement input:nth-child(2)").val("link");

JavaScript:
jQuery("#tk___kiaAlink input:nth-child(2)").val('https://archive.org/download/' + AudioID + '/' + valS1 + '.mp3') ;

The above code is in my JS on the dropdown element. It didn't work. It seems something wrong. I'll look up more.
 
Where and how are your AudioID and valS1 variables defined? Do they have correct values when doing console.log("Audio id "+AudioID); or alert("Audio id "+AudioID);
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top