# Change src inside an iframe html code dynamically (via cms)

**URL:** <https://forum.wixstudio.com/t/change-src-inside-an-iframe-html-code-dynamically-via-cms/63754>\
**Category:** Ask the community\
**Tags:** cms, code\
**Created:** [October 21, 2024, 10:01am UTC](https://forum.wixstudio.com/t/change-src-inside-an-iframe-html-code-dynamically-via-cms/63754 "2024-10-21T10:01:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaston](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gaston/32/24173_2.png) [@gaston](https://forum.wixstudio.com/u/gaston)\
**Post date:** [October 21, 2024, 10:01am UTC](https://forum.wixstudio.com/t/change-src-inside-an-iframe-html-code-dynamically-via-cms/63754/1 "2024-10-21T10:01:27Z")

</div>

Hi

I have a dynamic page with a database of 20 items. On the item pages I have an iframe that has the same code (a viewer for something) and i want to change a url inside this iframe.

I tried the following:

```javascript
$w.onReady(function () {
    // Access the current item in the dataset
    const currentItem = $w('#dynamicDataset').getCurrentItem();

    // Check if currentItem is defined
    if (currentItem) {
                $w('#html1').src = currentItem.myURL; 
    }
});

```

but it is not working. It does not recognize the urls defined in my database.  
What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [October 21, 2024, 1:08pm UTC](https://forum.wixstudio.com/t/change-src-inside-an-iframe-html-code-dynamically-via-cms/63754/2 "2024-10-21T13:08:28Z")

</div>

`$w.onReady` fires when the page loads, that happens before the Dataset is done fetching its data.

Try:

```js
$w('#dynamicDataset').onReady(() => {
    const currentItem = $w('#dynamicDataset').getCurrentItem()
    if (currentItem) $w('#html1').src = currentItem.myURL
})

```

---

<div class="post-metadata">

**Author:** ![codequeen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/codequeen/32/88960_2.png) [@codequeen](https://forum.wixstudio.com/u/codequeen)\
**Post date:** [October 22, 2024, 2:10am UTC](https://forum.wixstudio.com/t/change-src-inside-an-iframe-html-code-dynamically-via-cms/63754/3 "2024-10-22T02:10:13Z")

</div>

Is myURL the actual field key? Or is it myUrl? Or something else?

Does each URL have https? iFrames cannot have http, only https url’s.

---

<div class="post-metadata">

**Author:** ![gaston](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gaston/32/24173_2.png) [@gaston](https://forum.wixstudio.com/u/gaston)\
**Post date:** [October 28, 2024, 9:40pm UTC](https://forum.wixstudio.com/t/change-src-inside-an-iframe-html-code-dynamically-via-cms/63754/4 "2024-10-28T21:40:21Z")

</div>

Yes, the my.URL is the field name in my database and it is set to URL and all links have https

Actually by now I would be happy if I could just set the src Url of the iframe, even without any other code.

I tried it with Rich Content, but there it seems to get the iframe scaled to fit.

---

<div class="post-metadata">

**Author:** ![gaston](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gaston/32/24173_2.png) [@gaston](https://forum.wixstudio.com/u/gaston)\
**Post date:** [October 28, 2024, 9:44pm UTC](https://forum.wixstudio.com/t/change-src-inside-an-iframe-html-code-dynamically-via-cms/63754/5 "2024-10-28T21:44:41Z")

</div>

Mhhh, I can’t get t working with this. The iframe does not load up.  
**undefined** ’s server IP address could not be found.

I added your code ahead of the other one, but no avail.

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [October 28, 2024, 9:51pm UTC](https://forum.wixstudio.com/t/change-src-inside-an-iframe-html-code-dynamically-via-cms/63754/6 "2024-10-28T21:51:44Z")

</div>

The value is turning up undefined, this means that is not the correct field tag

Let’s log the data then, see what you get

```js
$w('#dynamicDataset').onReady(() => {
    console.log($w('#dynamicDataset').getCurrentItem())
})

```

You can also see the field tag within the Database view, when editing its properties

---

<div class="post-metadata">

**Author:** ![codequeen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/codequeen/32/88960_2.png) [@codequeen](https://forum.wixstudio.com/u/codequeen)\
**Post date:** [October 28, 2024, 10:48pm UTC](https://forum.wixstudio.com/t/change-src-inside-an-iframe-html-code-dynamically-via-cms/63754/7 "2024-10-28T22:48:22Z")

</div>

The field name and field key are two different variables. The field key is case sensitive .

A screenshot of your database and the page code, etc would help us see what you are seeing.
