Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Setting iframe src as a javascript variable

fortran_cookie

New Coder
Sorry if this is a stupid question- I have a project that displays a site in an iframe based on a text box input. I need some way to set the iframe src as a variable so that the iframe can display multiple sites. However, this does not work, and I've scoured the internet for a solution, and can't find it. Here's my code so far: (x is the variable from the text box)
HTML:
    <iframe id="linkhere" scrolling="yes" height="350" width ="1509" src=""></iframe>
   
    <script>
        document.getElementById("linkhere").src = x;
    </script>
Thanks.
 
Last edited by a moderator:
The easiest way to have an onclick for each (whatever a 'text box input' is) and call the same function and pass the src to that function.
JavaScript:
onclick ="controlFrame('google.com')"
and
function controlFrame(thesrc){
    <iframe id="linkhere" scrolling="yes" height="350" width ="1509" src="thesrc"></iframe>
}
 
Last edited by a moderator:
Back
Top Bottom