# Change iFrame src dynamically

**URL:** <https://forum.wixstudio.com/t/change-iframe-src-dynamically/37280>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [June 14, 2018, 6:22am UTC](https://forum.wixstudio.com/t/change-iframe-src-dynamically/37280 "2018-06-14T06:22:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![admin44](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@admin44](https://forum.wixstudio.com/u/admin44)\
**Post date:** [June 14, 2018, 6:22am UTC](https://forum.wixstudio.com/t/change-iframe-src-dynamically/37280/1 "2018-06-14T06:22:13Z")

</div>

**What I’m trying to do**  
I want to change the code of an iFrame dynamically, using a user’s input, after they press ‘submit’.

**What’s happening instead**  
I read three questions on this and answers by Yisrael and Ziv, spent an hour debugging, but sadly I can’t seem to get this to work. There doesn’t seem a way to change the code of an iFrame.

**My code**  
Below is a sample of the code (input names changed for simplicity).  
User enters a parameter in text box ‘userinput’, which I then try to set as part of the new code for an iFrame (myiframe).

After pressing the button, Debug1 shows correctly the new source. Debug2 shows the source returned from the iFrame. But sadly Debug2 always shows me a URL rather than the actual code that I set.

What am I doing wrong?

```javascript
export function submit_click(event, $w) {

let newsrc = '<iframe src=\"https://www.mywebsite.com=' + $w("#userinput").value + '\" ></iframe>';

$w("#debug1").text=newsrc;
$w("#myiframe").src = newsrc;

$w("#debug2").text= $w("#myiframe").src ; 
}

```

---

<div class="post-metadata">

**Author:** ![andreas-kviby](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andreas-kviby/32/790_2.png) [@andreas-kviby](https://forum.wixstudio.com/u/andreas-kviby)\
**Post date:** [June 14, 2018, 8:16am UTC](https://forum.wixstudio.com/t/change-iframe-src-dynamically/37280/2 "2018-06-14T08:16:43Z")

</div>

Hey  
The src parameter is just the url not the iframe and so on. So if you just set the src to [https://www.mywebsite.com=](https://www.mywebsite.com=)’ + $w(" [#userinput](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23userinput) ").value it should work better.

---

<div class="post-metadata">

**Author:** ![admin44](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@admin44](https://forum.wixstudio.com/u/admin44)\
**Post date:** [June 14, 2018, 2:01pm UTC](https://forum.wixstudio.com/t/change-iframe-src-dynamically/37280/3 "2018-06-14T14:01:18Z")

</div>

Hi Andreas. Thank you so much. I didn’t realise it. It works like a charm now!

For people who had the same problem, my mistake was in the ‘let newsc’ line. I simply had to remove the \<iframe bits. The correct code is below.  
Thanks Andreas!

> let newsrc = ‘[https://www.mywebsite.com=](https://www.mywebsite.com=)’ + $w(" [#userinput](https://www.wix.com/code/home/forum/search/posts%3Fquery=%23userinput) ").value’;

---

<div class="post-metadata">

**Author:** ![jackkammer](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jackkammer](https://forum.wixstudio.com/u/jackkammer)\
**Post date:** [June 6, 2019, 1:34am UTC](https://forum.wixstudio.com/t/change-iframe-src-dynamically/37280/4 "2019-06-06T01:34:51Z")

</div>

Howdy. Can you explain the page(s) and/or element(s) that made this work for you?
