Adding dynamic dataset to html1 element

Hi,

I am severely stumped. I have been reading pages on this forum for days but can’t figure out how to do what I require.

I have a dataset created - please see here:


I have a URL set field called Megaphone. I am a podcaster and want to add my podcast player in dynamically.

I then have a page ConnectTheRock (Title) with a HTML1 element. I want to get the URL into the HTML1 element. I can see lots of people showing code - but it just won’t work

Here is my page:

When I preview this I get the following error:

Could someone please tell me what I am doing wrong.

Thank you if you can save my nervous breakdown :stuck_out_tongue:

does url is the actual field key?

item = $w(‘#dataset1’).getCurrentItem().fieldKey;

You will find the field key on right clicking on the three dots for any one column
Then select “manage field”
then get the field key

Using the above code will assign any value in that field Key for the item

use
console.log($w(‘#dataset1’).getCurrentItem())

to get all the fieldkey for checking

Edit
typo missed parenthesis
You need it in order to run the function

Hi Salman2301,

Have tried what you said. Still no luck:

I now have:
$w.onReady( () => {

$w(" #dynamicDataset ").onReady( () => {
const itemUrl = $w(‘#dynamicDataset’).getCurrentItem.megaphone;
$w(’ #html1 ').src = itemUrl;

and I get this error:

Additionally, I added in the line:
console.log($w(’ #dataset1 ').getCurrentItem)

and I get:

This has been solved…very simple in the end:

$w(“#dynamicDataset”).onReady( () => {
const itemUrl = $w(‘#dynamicDataset’).getCurrentItem().megaphone;
$w(‘#html1’).src = itemUrl;

without the () after getCurrentItem, nothing would work.
So getCurrectItem() solves this issue.

Thank you Salman for all your assistance!

Hey :slight_smile:

Thanks for your message. I am glad you figured it out. Now I want to explain why it does so that you or others can learn a little bit about whats going on.

First, know that you can also write it this way:

const itemUrl = $w(‘#dynamicDataset’).getCurrentItem(); $w(‘#html1’).src = itemUrl.megaphone;

What the .megaphone does is specify what piece of information (column in your database collection/field key) you want to “grab” and “assign”. So whether it is after the getCurrentItem or itemUrl , now your html1 knows it needed to display whatever link was saved under the megaphone column.

Also know that “itemUrl” is just a variable or placeholder and it can be any word you want. For example even this would work:

const pizzaPlease = $w(‘#dynamicDataset’).getCurrentItem(); $w(‘#html1’).src = pizzaPlease.megaphone;

So now in “plain English” what it says is basically: Please get my current item from my dataset and call it pizzaPlease. Then get the information from megaphone column of my database collection for that current item I called pizzaPlease and display that information in my element called html1.

:slight_smile:

@admin51915 / @Code Queen Nayeli
please correct this code


$w.onReady( () => {
$w( “#dynamicDataset” ).onReady( () => {
const itemText = $w( “#dynamicDataset” ).getCurrentItem(); $w( ‘#input49’ ).value = itemText.title;
} );

You just forgot something.

$w.onReady(() => {
    $w("#dynamicDataset").onReady(() => {
        const itemText = $w("#dynamicDataset").getCurrentItem(); 
        $w('#input49').value = itemText.title;
    });
});